Notice
Recent Posts
Recent Comments
Dharma
[CppUnit] Console 모드시에 쓰이는 main 함수 모습 본문
기본적으로 cppUnit 에서 쓰이는 main 함수는 Text 모드 일때는 동일합니다. 각각의 세부 정보까지 표시하게 만든 버젼입니다. 다음부터 cppUnit Test Project 를 작성할때는 이부분을 복사해서 main 부분을 구성하면 똑같게 사용이 가능합니다.
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/ui/text/TestRunner.h> #include <cppunit/TestResult.h> #include <cppunit/TestResultCollector.h> #include <cppunit/BriefTestProgressListener.h> #include <cppunit/CompilerOutputter.h> int main (int argc, char * argv[]) { CPPUNIT_NS::TestResult controller ; CPPUNIT_NS::TestResultCollector result ; controller.addListener(&result); CPPUNIT_NS::BriefTestProgressListener progress ; controller.addListener(&progress); CPPUNIT_NS::TextUi::TestRunner runner; runner.addTest
( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest()); try { runner.run( controller ); CPPUNIT_NS::stdCOut() << "\n"; // Print test in a compiler compatible format. CPPUNIT_NS::CompilerOutputter outputter( &result,
CPPUNIT_NS::stdCOut() ); outputter.write(); // Uncomment this for XML output // std::ofstream file( "tests.xml" ); // CPPUNIT_NS::XmlOutputter xml( &result, file ); // xml.setStyleSheet( "report.xsl" ); // xml.write(); // file.close(); } catch ( std::invalid_argument &e ) / Test path not resolved { CPPUNIT_NS::stdCOut() << "\n" << "ERROR: " << e.what() << "\n"; return 0; } return result.wasSuccessful() ? 0:1 ; }
결과 입니다.
testbadc.exe
CalculateTest::testLoad : OK
CalculateTest::testDisplayData : assertion
CalculateTest::testLoad : OK
CalculateTest::testDisplayData : assertion
c:\crazia\work\testbadc\calculatetest.h(32) : error : Assertion
Test name: CalculateTest::testDisplayData
assertion failed
- Expression: pr.open(_T("TSS_TEST_pr_2.tot"))
Test name: CalculateTest::testDisplayData
assertion failed
- Expression: pr.open(_T("TSS_TEST_pr_2.tot"))
Failures !!!
Run: 2 Failure total: 1 Failures: 1 Errors: 0
Run: 2 Failure total: 1 Failures: 1 Errors: 0