我想在模块中使用 gtest 构建我的单元测试。每个模块通常是多个可测试单元的集合。在开发模块时,我一次创建一个单元测试,完成后我将它们连接到整个模块的一个单元测试中。
因此,为了便于说明,每个测试如下所示。
// file test1.cc
TEST1()
{
}
TESTn
{
)
#ifdef ISOLATED_TEST_COMPILE
int main()
{
/* google test boiler plate */
}
#endif
连接测试的文件看起来像这样
#include "test1.cc"
#include "testn.cc"
int main()
{
/* google test boiler plate */
}
所以我不希望能够让生成的 make 构建仅在命名时构建单个测试,并且不将单个测试包含在“all”目标中。整个模块统一单元测试构建应该位于 all 目标中。
我不希望 make all
重复编译单个测试。
I want to structure my unit tests, using gtest, in modules. each module is often a collection of multiple testible units. whilst developing a module i create a unit test at a time, and once finished I concatinate them into one unittest for the entire module.
So for some illustration, each test looks like this.
// file test1.cc
TEST1()
{
}
TESTn
{
)
#ifdef ISOLATED_TEST_COMPILE
int main()
{
/* google test boiler plate */
}
#endif
And a file that concatinates the test looks like this
#include "test1.cc"
#include "testn.cc"
int main()
{
/* google test boiler plate */
}
So I wan't to be able to get the generated make build to build individual tests only when named, and to not include individual tests in the "all" target. The entire module unity unit test build should be in the all target.
I don't want make all
to redundtly compile single tests.
发布评论
评论(1)
如果单元测试不在生产中,那么快速而肮脏的方法就是像上面那样使用#ifdef。
然后你只需像这样包装 ifdef 的定义即可。
If unit tests aren't in production, the quick and dirty would be to use #ifdef the same way you did above.
Then you just simply wrap the defines for the ifdefs like so.