在google测试中跨多个文件分开测试用例 [英] Separate test cases across multiple files in google test
问题描述
我是google的测试C ++框架的新。它很容易使用,但我想知道如何将案例分成多个测试文件。什么是最好的方法?
直接包含.cpp文件是一个选项。使用标题似乎没有什么...
欢迎任何帮助
创建一个只包含main的文件来运行测试。
// AllTests.cpp
#includegtest / gtest.h
int main(int argc,char ** argv)
{
testing :: InitGoogleTest(& argc,argv);
return RUN_ALL_TESTS();
}
然后将测试放入其他文件。您可以在文件中放入尽可能多的测试。每个类或每个源文件创建一个文件可以很好地工作。
// SubtractTest.cpp
#includesubtract .h
#includegtest / gtest.h
TEST(SubtractTest,SubtractTwoNumbers)
{
EXPECT_EQ(5,subtract(6,1)) ;
}
这需要所有的测试可以共享同一个主。如果你必须在那里做一些特别的事情,你必须有多个构建目标。
I'm new in google test C++ framework. It's quite easy to use but I'm wondering how to separate the cases into multiple test files. What is the best way?
Include the .cpp files directly is an option. Using a header seems that does nothing...
Any help is welcome
Create one file that contains just the main to run the tests.
// AllTests.cpp
#include "gtest/gtest.h"
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Then put the tests into other files. You can put as many tests as you like in a file. Creating one file per class or per source file can work well.
// SubtractTest.cpp
#include "subtract.h"
#include "gtest/gtest.h"
TEST(SubtractTest, SubtractTwoNumbers)
{
EXPECT_EQ(5, subtract(6, 1));
}
This does require that all tests can share the same main. If you have to do something special there, you will have to have multiple build targets.
这篇关于在google测试中跨多个文件分开测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!