Visual Studio Community Edition 2019没有找到任何测试
我在Visual Studio 2019社区版中创建了一个名为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);
}
可执行文件可正常工作。它运行测试或只是说“你好”。问题是VS找不到任何测试,因此我无法使用测试资源管理器。有人知道如何解决这个问题吗?我已将项目上传到GitHub:
I have created a C++ project called Googletest in Visual Studio 2019 Community Edition. In the project I have installed Gmock as a nugget(gmock 1.11.0). I have two cpp files(Googletest.cpp and 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);
}
The executable works properly. It runs the test or just says "Hello". The problem is that VS doesn't find any test, so that I can't use the test explorer. Does anyone know how to fix the issue? I have uploaded the project on github: https://github.com/tellass567/vs-googletest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已经安装了用于Google测试的测试适配器并且无法发现Google测试,请确保测试名称以测试或测试结束,否则测试适配器无法发现单元测试,
您可以添加替代测试名称Regexes在工具&gt;选项&gt;用于Google测试的测试适配器帮助测试适配器发现单元测试,请参见。
If you have installed Test Adapter for Google Test and it can't discover Google tests, be sure the test names end with Test or Tests, otherwise Test Adapter is not able to discover unit tests
You may add alternative test name RegExes in Tools > Options > Test Adapter for Google Test to help Test Adapter to discover unit tests, see Trait Regexes.