[英]How to run CPPUnit unit tests
我已经使用CPPUnit编写了一些c ++单元测试。
但是我不知道如何运行那些。
有没有像Nunit-gui这样的工具?
目前,我已经在DLL中编写和打包了测试。
当我在Google上搜索时,我发现了这个http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html
但是我无法理解它如何从DLL获取测试。
将您的TestCases分组到TestSuite中,编写main(),进行编译,针对cppunit库进行链接,然后从命令行运行可执行文件。
这是主要功能的示例:
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文件。 然后,在Visual Studio项目中,您需要设置一些内容
1)。 在Visual Studio项目的位置, 项目属性> C / C ++>常规>其他包含目录中 ,在cppunit文件内提供包含文件夹的路径。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.