我在gtest中有一个测试套件。我的测试夹具类有两个测试,一个是Test_F(功能),Test_F(性能)。 我的实现方式是 Test_F(性能)依赖于 Test_F(功能)的运行。 我想处理这种情况,当 Test_F(功能)被禁用时。所以,我的方法是从 Test_F(性能)内部调用 Test_F(功能)。 我不确定,这是如何在 gtest 中完成的,调用 test_function,在另一个 test_function 内。 如有任何帮助,我们将不胜感激。
最佳答案
据我所知,没有选项可以在另一个测试函数中调用测试函数。但是,要在测试用例之间共享代码,您可以在测试套件中定义辅助方法:
class FooBarTestSuite : public ::testing::Test {
public:
TestSuite() {
// init code goes here
// foo and bar are accessible here
}
~TestSuite() {
// deinit code goes here
// foo and bar are accessible here
}
void CommonCode() {
// common test case code here
// foo and bar are accessible here
}
ClassFoo foo{};
ClassBar bar{};
};
TEST_F(FooBarTestSuite, PerformanceTest) {
CommonCode();
// performance-specific code here
}
TEST_F(FooBarTestSuite, FunctionalTest) {
CommonCode();
// functional-specific code here
}
要运行特定的测试用例,请使用 --gtest_filter=*Performace*
或 --gtest_filter=*Functional*
作为参数。
关于c++ - 在gtest中调用另一个TEST_F中的一个TEST_F,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66524625/