c++ - 在gtest中调用另一个TEST_F中的一个TEST_F

标签 c++ unit-testing jenkins googletest

我在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/

相关文章:

jenkins - 如何将 Gradle 构建 currentVersion 写入文件

c++ - Web 应用程序和 C++

c# - NUnit 测试事件参数数据

c++ - Qt C++ 在函数模板中使用约束

javascript - 创建可单元测试的闭包的最佳模式?

ios - xCode 7.1 中警报的 UITesting

android - Maven不会因引入的编译错误而失败

deployment - 我如何让Jenkins在另一台服务器上运行脚本并监视结果?

c++ - 两个应用程序可以通过 UDP 数据包进行通信吗?

c++ - 此处不允许使用 'asm' 声明