您如何选择要运行的特定 Google Mock 测试用例/单元测试?

Len*_*art 3 c++ unit-testing googletest

我有多个单元测试,每个测试都在一个单独的文件中。

我的标准单元测试之一如下所示:

#include "gmock/gmock.h"
#include "gtest/gtest.h"

class ClassAUnitTest : public ::testing::Test {
protected:
    // Per-test-case set-up.
    // Called before the first test in this test case.
    // Can be omitted if not needed.
    static void SetUpTestCase() {
        //..
    }

    // Per-test-case tear-down.
    // Called after the last test in this test case.
    // Can be omitted if not needed.
    static void TearDownTestCase() {
        //..
    }

    // You can define per-test set-up and tear-down logic as usual.
    virtual void SetUp() {  }
    virtual void TearDown() {
}
    // Some expensive resource shared by all tests.
    //..
};

TEST_F(ClassAUnitTest, testCase1) {
    // Assign .. Act .. Assert.
}
Run Code Online (Sandbox Code Playgroud)

我知道的方法是将 DISABLED_ 放在测试用例前面,如下所示:

TEST_F(ClassAUnitTest, DISABLED_testCase1) {
    // Assign .. Act .. Assert.
}
Run Code Online (Sandbox Code Playgroud)

然而,在处理一个失败的单元测试时运行所有测试是非常不切实际的。

我使用带有 Gmock 1.7.0 的 Visual Studio Ultimate 2013。

问题:如何轻松选择要运行哪些单元测试或特定测试,哪些不运行?

BЈо*_*вић 5

首先,您的单元测试应该快如闪电。否则人们不会处决他们。

选择测试中所述,您可以使用--gtest_filter=选项。在您的具体情况下:--gtest_filter=ClassAUnitTest.*