简体   繁体   中英

Visual Studio Community Edition 2019 doesn't find any tests

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM