Visual Studio Community Edition 2019 找不到任何测试



我在Visual Studio 2019 Community Edition中创建了一个名为Googletest的c++项目。在这个项目中,我将Gmock作为一个块安装(Gmock 1.11.0)。我有两个cpp文件(Googletest.cpp和Test.cpp)。

Googletest.cpp

#include "gtest/gtest.h"
#include <iostream>
int main(int argc, char** argv) {
if (strcmp("test", argv[1]) == 0)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
else
{
std::cout << "Hello!" << std::endl;
}
}

Test.cpp

#include "gtest/gtest.h"
TEST(FooTestSuite, Foo1) {
ASSERT_EQ(1, 1);
}

可执行文件工作正常。它运行测试或者只是说"hello"。问题是VS没有找到任何测试,所以我不能使用测试资源管理器。有人知道如何解决这个问题吗?我已经把项目上传到github: https://github.com/tellass567/vs-googletest

如果您已经为Google Test安装了测试适配器,但它无法发现Google测试,请确保测试名称以Test或tests结尾,否则测试适配器无法发现单元测试

TEST(FooTests, Foo1) {
ASSERT_EQ(1, 1);
}

您可以在Tools>选择比;Test Adapter for Google Test要帮助Test Adapter发现单元测试,请参见Trait正则表达式。

最新更新