c++ - Googletest 不运行测试夹具

标签 c++ unit-testing testing googletest

我正在尝试使用 googletest 在 C++ 中进行单元测试。我在 ClusteringTest.h 中定义了一个文本夹具:

#include <gtest/gtest.h>

namespace EnsembleClustering {

class ClusteringTest: public ::testing::Test {

    ClusteringTest() {};

    virtual ~ClusteringTest() {};

    virtual void SetUp() {

    };

    virtual void TearDown() {

    };

};

TEST_F(ClusteringTest, doesGTestWork) {
    EXPECT_EQ(42, 42);
}


} /* namespace EnsembleClustering */

在我的主要功能中,我调用:

 ::testing::InitGoogleTest(&argc, argv);
 return RUN_ALL_TESTS();

结果是:

running EnsembleClustering
[==========] Running 0 tests from 0 test cases.
[==========] 0 tests from 0 test cases ran. (1 ms total)
[  PASSED  ] 0 tests.

为什么我的测试没有运行?

最佳答案

您需要将 header ClusteringTest.h 包含到某个 .cpp 文件中以使其具体化,并创建一个编译单元。

关于c++ - Googletest 不运行测试夹具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13840278/

相关文章:

testing - 如何比较测试网站和实时网站

c++ - OpenCV 的 SiftDescriptorExtractor 如何转换描述符值?

java - JUnit 4 : Set up things in a test suite before tests are run (like a test's @BeforeClass method, 仅用于测试套件)

c++ - cURL 返回上次请求的数据

python - 具有从配置文件中读取 configparser 的单元测试 python 代码

asp.net-mvc - ASP.NET MVC 中的模拟 Controller.Url.Action(string, string, object, string)

go - 函数 TestMain 未运行

ruby - 哪里可以详细学习Cucumber?

c++ - 使用 Boost 构建单元测试时出现链接器错误

C++模板和结构问题