ut可以提高代码的质量。为以后代码的改动提供保证。但是并不能保证代码完全没有bug。
ut的框架是这样的。
//maintest.cpp
CppUnit::TextUi::TestRunner runner;
//
CppUnit::TestFactoryRegistry ®MsgTest = CppUnit::TestFactoryRegistry::getRegistry("MSG_TEST");
....
..
//
runner.addTest( regMsgTest.makeTest() );
//
runner.run();
//msg_test.cpp
#define MSG_TEST_DECLARE(MsgClass) \
CPPUNIT_TEST_SUITE(MsgClass); \
CPPUNIT_TEST( testMsg ); \
CPPUNIT_TEST_SUITE_END()
#define MSG_TEST_REG(MsgClass) \
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MsgClass, "MSG_TEST")
class MsgTest_c : public CppUnit::TestFixture
{
pubic:
virtual void setUp();
virtual void tearDown() {};
virtual void testMsg() = 0;
};
阅读(759) | 评论(0) | 转发(0) |