我使用 CPPUnit 编写了一些 c++ 单元测试。
但我不明白如何运行这些。
有没有像 Nunit-gui 这样的工具?
目前我已经在 DLL 中编写并打包了测试。
当我用谷歌搜索时,我发现了这个http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html
但我无法理解它如何从 DLL 中获取测试。
我使用 CPPUnit 编写了一些 c++ 单元测试。
但我不明白如何运行这些。
有没有像 Nunit-gui 这样的工具?
目前我已经在 DLL 中编写并打包了测试。
当我用谷歌搜索时,我发现了这个http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html
但我无法理解它如何从 DLL 中获取测试。
将您的 TestCases 分组到 TestSuite,编写 main(),编译,链接 cppunit 库并从命令行运行可执行文件。
下面是一个 main 函数的例子:
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
int main( int ac, char **av )
{
//--- Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
//--- Add a listener that colllects test result
CPPUNIT_NS::TestResultCollector result;
controller.addListener( &result );
//--- Add a listener that print dots as test run.
CPPUNIT_NS::BriefTestProgressListener progress;
controller.addListener( &progress );
//--- Add the top suite to the test runner
CPPUNIT_NS::TestRunner runner;
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
runner.run( controller );
return result.wasSuccessful() ? 0 : 1;
}
如果你真的想要一个 GUI,有QxRunner。
如果您在 Windows 上并且正在测试 C++,我建议人们在 Visual Studio 中使用 cppunit。如何在 Visual Studio 中配置 cppunit 以及如何通过示例使用它?如果你已经下载了 cppunit 文件。然后在您的视觉工作室项目中,您需要设置一些东西
1)。在 Visual Studio 项目位置的 cppunit 文件中提供包含文件夹的路径,项目属性 > C/C++ > 常规 > 附加包含目录。
2)。在 Visual Studio 项目位置的 cppunit 文件中提供 lib 文件夹的路径,项目属性 > 链接器 > 常规 > 附加库目录。
3)。在 Visual Studio 项目的位置添加文件“cppunit.lib”,项目属性 > 链接器 > 输入 > 附加依赖项。
按照以下链接中的分步程序进行操作
http://www.areobots.com/unit-testing-with-cppunit-visual-studio-configuration/
http://www.areobots.com/how-to-do-unit-testing-with-cppunit-with-example/
如以下链接所述 http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/ checkout /sync4j/tools/cppunit/INSTALL-WIN32.txt?rev=1.1.1.1
可以使用 TestPlugInRunner