简体   繁体   English

使用googletest立即为多个测试模块运行单元测试

[英]Using googletest to run unit-tests for multiple tested modules at once

I'm working on a large C++ project which contains more than 50 libraries and executables. 我正在开发一个包含50多个库和可执行文件的大型C ++项目。 I am starting to add googletest tests for each of these modules. 我开始为每个模块添加googletest测试。 I read that google recommends putting the tests in an executables and not in libraries to make life easier. 我读到谷歌建议将测试放在可执行文件而不是库中,以使生活更轻松。 Creating a separate executable for each separate components I would get more than 50 test executables and in order to run them all at once I would need to create an external script which would also need to combine their output to a single one. 为每个单独的组件创建一个单独的可执行文件我将获得50多个测试可执行文件,并且为了一次性运行它们,我需要创建一个外部脚本,它还需要将它们的输出组合到一个单独的脚本中。 Is that the recommended thing to do? 这是推荐的事情吗?

Or should I create a library for tests of each separate module and link all these libs to a single tests executable? 或者我应该为每个单独模块的测试创建一个库,并将所有这些库链接到单个测试可执行文件? But then running tests for a single module becomes less convinient. 但是,对单个模块运行测试变得不那么方便了。 I would need to build all the tests and specify to the main test executable through the gtest_filter flag which tests should be executed at this time. 我需要构建所有测试并通过gtest_filter标志指定主测试可执行文件,此时应执行哪些测试。

It would really help me to hear how other people do this and what is the best practice here. 这真的有助于我了解其他人如何做到这一点以及这里的最佳做法是什么。

Thank you 谢谢

[...] and in order to run them all at once I would need to create an external script which would also need to combine their output to a single one. [...]并且为了一次性运行它们,我需要创建一个外部脚本,它还需要将它们的输出组合成一个。

Maybe it's not actually necessary to combine the output into a single file. 也许实际上并不需要将输出组合成单个文件。 For example with Jenkins you can specify a wildcard pattern for the Google Test output files. 例如,使用Jenkins,您可以为Google Test输出文件指定通配符模式。

So if you actually just want to see the Google Test results in Jenkins (or Hudson or whatever CI tool you use), this might be a possible solution: 因此,如果您真的只想在Jenkins(或Hudson或您使用的任何CI工具)中看到Google测试结果,这可能是一个可能的解决方案:

You would run all of your test executables from a simple script (or even from a Make rule), with parameter --gtest_output=xml: followed by a directory name (ie. ending with a slash). 您可以从一个简单的脚本(甚至是Make规则)运行所有测试可执行文件,参数--gtest_output=xml:后跟一个目录名 (即以斜杠结尾)。 Every test executable will then write an own XML file into that directory, and you can then configure your CI tool to read all files from that directory. 然后,每个测试可执行文件都会将自己的XML文件写入该目录,然后您可以配置CI工具以读取该目录中的所有文件。

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

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