如何让谷歌测试在QtCreator中执行多个测试文件

How to get Google Test to execute multiple test files in QtCreator?

本文关键字:测试 执行 文件 谷歌 QtCreator      更新时间:2023-10-16

我在Qt Creator中使用了Google Test,并编写了两个测试文件,一个是tst_a.h(默认生成)。
另一个文件是我自动创建的 tst_b.h,但在单元测试期间只执行 tst_a.h
如何让谷歌测试执行tst_b.h
请查找上述文件的内容。

这是tst_a.h

#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#include "Decimal.hpp"
using namespace testing;
TEST(contractTestCase, contractTestSet)
{
    EXPECT_EQ(1, 1);
    ASSERT_THAT(0, Eq(0));
}

这是tst_b.H

#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
using namespace testing;
TEST(testNormal, contractNormalTestSet)
{
    EXPECT_EQ(1, 1);
}

在头文件中编写测试时,这些头文件需要包含在 cpp 中,以便编译器可以看到它们。默认测试设置以 main 开头.cpp您可以在其中为新的 .h 文件添加包含。