简体   繁体   English

如何运行CPPUnit单元测试

[英]How to run CPPUnit unit tests

I have written few c++ Unit tests using CPPUnit. 我已经使用CPPUnit编写了一些c ++单元测试。

But I do not understand how to run those. 但是我不知道如何运行那些。

Is there any tool like Nunit-gui? 有没有像Nunit-gui这样的工具?

Currently I have written and packed tests in a DLL. 目前,我已经在DLL中编写和打包了测试。

When i google i found this http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html 当我在Google上搜索时,我发现了这个http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html

But I am not able to understand how it gets tests from a DLL. 但是我无法理解它如何从DLL获取测试。

Group your TestCases into TestSuite, write a main(), compile, link against the cppunit library and run the executable from the command-line. 将您的TestCases分组到TestSuite中,编写main(),进行编译,针对cppunit库进行链接,然后从命令行运行可执行文件。

Here is an example of a main function.: 这是主要功能的示例:

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;
}

If you really want a GUI, there is QxRunner . 如果您确实需要GUI,则可以使用QxRunner

I would suggest people to use cppunit in visual studio if you are on windows and if you are testing for C++. 如果您在Windows上并且正在测试C ++,我建议人们在Visual Studio中使用cppunit。 How to configure cppunit in visual studio and how to use it with example? 如何在Visual Studio中配置cppunit以及如何在示例中使用它? if you have downloaded the cppunit file. 如果您已经下载了cppunit文件。 Then in your visual studio project you need to set few things 然后,在Visual Studio项目中,您需要设置一些内容

1). 1)。 Give the path of include folder inside your cppunit file at location of your visual studio project, Project properties > C/C++ > General > Additional include directories. 在Visual Studio项目的位置, 项目属性> C / C ++>常规>其他包含目录中 ,在cppunit文件内提供包含文件夹的路径

2). 2)。 Give the path of lib folder inside your cppunit file at location of your visual studio project, Project properties > Linker > General > Additional library directories. 在Visual Studio项目的位置, 项目属性>链接器>常规>其他库目录中 ,在cppunit文件中提供lib文件夹的路径

3). 3)。 Add a file "cppunit.lib" at location of your visual studio project, Project properties > Linker > Input > Additional Dependencies. 在Visual Studio项目的位置, 项目属性>链接器>输入>其他依赖项中添加文件“ cppunit.lib”

Follow the step by step procedure in the link below 请按照以下链接中的分步过程进行操作

http://www.areobots.com/unit-testing-with-cppunit-visual-studio-configuration/ 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://www.areobots.com/how-to-do-unit-testing-with-cppunit-with-example/

As mentioned in following link http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/ checkout /sync4j/tools/cppunit/INSTALL-WIN32.txt?rev=1.1.1.1 如以下链接所述:http: //cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/ checkout /sync4j/tools/cppunit/INSTALL-WIN32.txt?rev=1.1.1.1

TestPlugInRunner can be used 可以使用TestPlugInRunner

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM