[英]Google Unit Test Confusion
I'm a bit confused about where the unit tests should be. 我对单元测试应该在哪里感到有些困惑。 All the documentation leads me to believe that I must create a Test Project.
所有文档使我相信必须创建一个测试项目。 REALLY?
真? With JUnit we just created a Test package (folder) inside our application project and the tests would run with every build.
使用JUnit,我们只是在应用程序项目中创建了一个Test包(文件夹),并且测试将在每个构建版本中运行。
I'm new to C++ and trying to figure out how Google Test works. 我是C ++的新手,试图弄清楚Google Test的工作原理。 I've found a lot of really good questions and answers here on SO and Yes I have read the Google Test documentation but I'm still confused about this one thing:
我在SO上找到了很多非常好的问题和答案,是的,我已经阅读了Google Test文档,但是我仍然对此感到困惑:
Can I create a subfolder in my project with all my unit tests, such that they will execute with each build?
我可以使用所有单元测试在项目中创建一个子文件夹,以便它们在每次构建时都执行吗?
If YES then can you please help me find the needed information/example? 如果是,那么您能帮我找到所需的信息/示例吗?
OK, I found in the Primer here: https://github.com/google/googletest/blob/master/googletest/docs/primer.md 好的,我在这里的Primer中找到了: https : //github.com/google/googletest/blob/master/googletest/docs/primer.md
Once you are able to compile the Google Test library, you should create a project or build target
for your test program . 能够编译Google Test库后,您应该为测试程序创建一个项目
or build target
。 This is promising! 这是有希望的! Maybe the documentation just keeps mentioning creating a project and doesn't make it clear that the test code can be in your application project?
也许文档只是提到创建项目而没有明确说明测试代码可以在您的应用程序项目中?
Nope!
不! Just wishful thinking on my part, as πάντα-ῥεῖ pointed out in his answer.
正如πάντα-ῥεῖ在他的回答中所指出的那样,只是我的一厢情愿。
"All the documentation leads me to believe that I must create a Test Project. REALLY?"
“所有文档使我相信我必须创建一个测试项目。真的吗?”
Yes with c++ you have to, because there's no generic test runner executable artifact, as it's kind of provided with JUnit. 是的,对于c ++,您必须这样做,因为没有通用的测试运行器可执行工件,因为JUnit提供了这种工件。
Can I create a subfolder in my project with all my unit tests, such that they will execute with each build?
我可以使用所有单元测试在项目中创建一个子文件夹,以便它们在每次构建时都执行吗?
I would recommend to put all the test case classes (as plain .cpp
sources) into a separate project, and link with the classes under test from a separate library project. 我建议将所有测试用例类(作为纯
.cpp
源代码)放入一个单独的项目中,并与一个单独的库项目中的被测类链接。 Include gtest_all.cc
with the main()
function, or link against the gtest
library, with the test project. 在
main()
函数中包含gtest_all.cc
,或者在测试项目中包含gtest_all.cc
gtest
库的链接。
To run the test cases add running the UnitTester
artifact build from that project as an additional build step. 要运行测试用例,请添加从该项目运行
UnitTester
工件构建作为附加的构建步骤。
"Maybe the documentation just keeps mentioning creating a project and doesn't make it clear that the test code can be in your application project."
“也许文档只是提到创建项目,而没有明确说明测试代码可以在您的应用程序项目中。”
Well, that depends a lot upon your actual IDE/build system what is a single project (I prefer to use this term for single artifacts as a result), and a solution (or workspace ) for a related collection of them. 嗯,这很大程度上取决于您的实际IDE /构建系统,这是一个项目(我更倾向于将此术语用于单个工件),以及一个与它们相关的集合的解决方案 (或工作区 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.