Visual Studio Community Edition 2019没有找到任何测试

发布于 2025-01-22 16:29:02 字数 751 浏览 2 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天赋异禀 2025-01-29 16:29:02

如果您已经安装了用于Google测试的测试适配器并且无法发现Google测试,请确保测试名称以测试或测试结束,否则测试适配器无法发现单元测试,

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

您可以添加替代测试名称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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文