我有多个单元测试,每个类在单独的文件中。
我的标准单元测试之一如下所示:
#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.
}
我知道的方法是将DISABLED_放在测试用例的前面,如下所示:
TEST_F(ClassAUnitTest, DISABLED_testCase1) {
// Assign .. Act .. Assert.
}
但是,在一项失败的单元测试中运行所有测试非常不切实际。
我将Visual Studio Ultimate 2013与Gmock 1.7.0一起使用。
问题:如何轻松选择要运行哪些单元测试或特定测试,哪些不运行?
首先,您的单元测试应该快如闪电。否则,人们将不会执行它们。
如选择测试中所述,您可以--gtest_filter=
选择使用选项。在您的特定情况下:--gtest_filter=ClassAUnitTest.*
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句