[英]Beginning Code::blocks and UnitTest++
I'm about to start a C++ project but I'm stuck at the basics. 我将要开始一个C ++项目,但我仍停留在基础知识上。
I want to use the (linux) Code::Blocks IDE, and it's easy to create a normal project. 我想使用(linux)Code :: Blocks IDE,创建普通项目很容易。 However I want to do TDD using the UnitTest++ framework, and I don't know how to set everything up cleanly. 但是我想使用UnitTest ++框架进行TDD,而且我不知道如何将所有内容进行干净设置。
I've already asked a question about where to put the UnitTest::RunAllTests()
command, and they told me the best place is the main()
of a separate program. 我已经问了一个关于将UnitTest::RunAllTests()
命令放在哪里的问题 ,他们告诉我最好的地方是一个单独程序的main()
。
How do I go about doing this in Code::Blocks? 我该如何在Code :: Blocks中执行此操作? I think I need to create 2 projects: 我想我需要创建2个项目:
main()
; 具有其自己的main()
的“实际”项目; main()
with UnitTest::RunAllTests()
inside. 包含测试和main()
的单元测试项目,其中包含UnitTest::RunAllTests()
。 Then somehow have the first project build and run the second during its build process. 然后以某种方式构建第一个项目,并在其构建过程中运行第二个项目。 I don't know how to do that yet but I can find out on my own. 我还不知道该怎么做,但是我可以自己找到答案。
My questions are: 我的问题是:
I'll partly answer my own questions, as I've managed to get everything working. 我将部分回答自己的问题,因为我设法使所有工作正常进行。
UnitTest::RunAllTests()
. 然后,我为所有单元测试创建了一个测试项目,其主要功能包含著名的UnitTest::RunAllTests()
。 I put $exe_output
as a post-build process here, in order to have the tests executed automatically every time I build this project. 我在这里放置$exe_output
作为构建后的过程,以使每次构建此项目时自动执行测试。 With these settings I can work on my tests and on the real code, and I only have to build the real one to have the updated tests executed. 通过这些设置,我可以在测试和真实代码上进行工作,并且只需要构建真实的代码即可执行更新的测试。 Any failing test will also make the build fail. 任何失败的测试也会使构建失败。
Now two questions remain: "is this the best approach?" 现在还有两个问题:“这是最好的方法吗?” and "right now each project lives in a different directory. Is it wiser to leave it this way or should I put each test in the same folder as the real code to be tested?" 和“现在每个项目都位于不同的目录中。以这种方式保留它是否更明智?还是应该将每个测试与要测试的真实代码放在同一文件夹中?”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.