如何运行 CPPUnit 单元测试

发布于 2024-07-26 05:34:45 字数 343 浏览 2 评论 0原文

我使用 CPPUnit 编写了一些 C++ 单元测试。

但我不明白如何运行它们。

有没有类似 Nunit-gui 的工具?

目前我已经在 DLL 中编写并打包了测试。

当我谷歌时,我发现了这个 http://cppunit.sourceforge.net/doc/lastest/ cppunit_cookbook.html

但我无法理解它如何从 DLL 获取测试。

I have written few c++ Unit tests using CPPUnit.

But I do not understand how to run those.

Is there any tool like Nunit-gui?

Currently I have written and packed tests in a DLL.

When i google i found this http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html

But I am not able to understand how it gets tests from a DLL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一桥轻雨一伞开 2024-08-02 05:34:45

将您的测试用例分组到 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

Group your TestCases into TestSuite, write a main(), compile, link against the cppunit library and run the executable from the command-line.

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.

却一份温柔 2024-08-02 05:34:45

如果您在 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/< /a>

I would suggest people to use cppunit in visual studio if you are on windows and if you are testing for C++. How to configure cppunit in visual studio and how to use it with example? if you have downloaded the cppunit file. Then in your visual studio project you need to set few things

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.

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.

3). Add a file "cppunit.lib" at location of your visual studio project, Project properties > Linker > Input > Additional Dependencies.

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/how-to-do-unit-testing-with-cppunit-with-example/

ゃ人海孤独症 2024-08-02 05:34:45

正如以下链接中提到的
http://cvs.forge.objectweb.org/cgi-bin/viewcvs .cgi/checkout/sync4j/tools/cppunit/INSTALL-WIN32.txt?rev=1.1.1.1

TestPlugInRunner即可使用

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

TestPlugInRunner can be used

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文