1 新建一个 win32 项目 windows应用程序 选择空工程.完成
2 设置工程属性,使用多字节字符集 在共享 DLL 中使用 MFC 链接器->输入->附加依赖项 CppUnitd.lib WinTestRunnerd.lib
添加一个Driver.cpp
//Driver.cpp #include <WinTestRunner/WinTestRunner.h> //#include "MyTestSutite.h" #include "vh_test_case.h" class TestDriver: public CppUnit::WinTestRunnerApp { void TestMain() { CppUnit::WinTestRunner runner; // runner.addTest(MyTestSutite::suite()); runner.addTest(vh_test_case::suite()); //这里还可以多添加几个 runner.run(); } }; TestDriver theDriver;
// vh_test_case.h #pragma once #include <CppUnit/TestCase.h> class vh_test_case: public CppUnit::TestCase { public: vh_test_case(const std::string& name); ~vh_test_case(void); void setUp(); void tearDown(); static CppUnit::Test* suite(); void test1(); };
//vh_test_case.cpp #include "vh_test_case.h" #include <CppUnit/TestCaller.h> #include <CppUnit/TestSuite.h> using namespace std; vh_test_case::vh_test_case(const std::string& name): CppUnit::TestCase(name) { } vh_test_case::~vh_test_case(void) { } CppUnit::Test* vh_test_case::suite() { CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("vh_test_case"); // pSuite->addTest(vh_test_case1::suite()); //这个东西就像树形结构一样 你可以多加几层 下一个类的写法和这个一样 CppUnit_addTest(pSuite, vh_test_case, test1); //这层下你的测试函数 // CppUnit_addTest(pSuite, vh_test_case, test2); // CppUnit_addTest(pSuite, vh_test_case, test3); return pSuite; } void vh_test_case::test1() { } void vh_test_case::setUp() { } void vh_test_case::tearDown() { }