Google Test not finding any tests
Asked Answered
A

4

9

So I'm working on creating my first unit tests. I'm using Google Test, the version that is currently built into Visual Studio 2017. This is an attempt at a proof of concept, so super simple.

I have a project in the solution for the test code: test.cpp

#include "pch.h"
#include "../ConsoleApplication1/ConsoleApplication1.cpp"

TEST(SumTest, FirstTest) {
  EXPECT_EQ(6, sum(2, 4));
}

TEST(SumTest, SecondTest) {
    EXPECT_EQ(1, 1);
    EXPECT_TRUE(true);
}

And I have a simple method to test in ConsoleApplication1.cpp

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int sum(int a, int b);

int main()
{
    int x = sum(2, 4);
    printf("The answer is: %d \n", x);

}

int sum(int a, int b) {
    return a + b;
}

Everything compiles fine, but when I click 'Run All' from the Test Explorer menu, I get the following output:

[5/7/2018 4:17:42 PM Informational] ------ Run test started ------
[5/7/2018 4:17:43 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:17:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:17:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:17:43 PM Informational] Running 0 tests...
[5/7/2018 4:17:43 PM Informational] Google Test execution completed, overall duration: 00:00:00.3666448
[5/7/2018 4:17:43 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:17:44 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:17:44 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:17:44 PM Informational] ========== Run test finished: 0 run (0:00:01.9324761) ==========
[5/7/2018 4:20:39 PM Informational] ------ Discover test started ------
[5/7/2018 4:20:40 PM Informational] Test Adapter for Google Test: Test discovery starting...
[5/7/2018 4:20:40 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:20:40 PM Informational] Test discovery completed, overall duration: 00:00:00.3954411
[5/7/2018 4:20:40 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:20:40 PM Informational] ========== Discover test finished: 0 found (0:00:01.8597435) ==========
[5/7/2018 4:20:47 PM Informational] ------ Discover test started ------
[5/7/2018 4:20:48 PM Informational] Test Adapter for Google Test: Test discovery starting...
[5/7/2018 4:20:49 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:20:49 PM Informational] Test discovery completed, overall duration: 00:00:00.3670275
[5/7/2018 4:20:49 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:20:49 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:20:49 PM Informational] ========== Discover test finished: 0 found (0:00:01.873206) ==========
[5/7/2018 4:21:36 PM Informational] ------ Run test started ------
[5/7/2018 4:21:37 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:21:38 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:21:38 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:21:38 PM Informational] Running 0 tests...
[5/7/2018 4:21:38 PM Informational] Google Test execution completed, overall duration: 00:00:00.3844604
[5/7/2018 4:21:38 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:21:38 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:21:38 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:21:38 PM Informational] ========== Run test finished: 0 run (0:00:02.0203611) ==========
[5/7/2018 4:27:21 PM Informational] ------ Run test started ------
[5/7/2018 4:27:34 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:27:35 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:27:35 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:27:35 PM Informational] Running 0 tests...
[5/7/2018 4:27:35 PM Informational] Google Test execution completed, overall duration: 00:00:00.6936342
[5/7/2018 4:27:35 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:27:35 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:27:35 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:27:35 PM Informational] ========== Run test finished: 0 run (0:00:14.3144745) ==========
[5/7/2018 4:27:59 PM Informational] ------ Run test started ------
[5/7/2018 4:28:11 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:28:11 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:28:11 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:28:11 PM Informational] Running 0 tests...
[5/7/2018 4:28:11 PM Informational] Google Test execution completed, overall duration: 00:00:00.6451099
[5/7/2018 4:28:11 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:28:12 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:28:12 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:28:12 PM Informational] ========== Run test finished: 0 run (0:00:12.9601734) ==========
[5/7/2018 4:29:59 PM Informational] ------ Run test started ------
[5/7/2018 4:30:59 PM Error] Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Failed to initialize client proxy: could not connect to test process.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)
[5/7/2018 4:30:59 PM Error] Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Failed to initialize client proxy: could not connect to test process.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)
[5/7/2018 4:30:59 PM Informational] ========== Run test finished: 0 run (0:01:00.2319577) ==========
[5/7/2018 4:34:34 PM Informational] ------ Discover test started ------
[5/7/2018 4:34:36 PM Informational] Test Adapter for Google Test: Test discovery starting...
[5/7/2018 4:34:36 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:34:36 PM Informational] Test discovery completed, overall duration: 00:00:00.3801077
[5/7/2018 4:34:36 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:36 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:36 PM Informational] ========== Discover test finished: 0 found (0:00:01.89196) ==========
[5/7/2018 4:34:41 PM Informational] ------ Run test started ------
[5/7/2018 4:34:42 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:34:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:34:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:34:43 PM Informational] Running 0 tests...
[5/7/2018 4:34:43 PM Informational] Google Test execution completed, overall duration: 00:00:00.3975222
[5/7/2018 4:34:43 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:43 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:43 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:34:43 PM Informational] ========== Run test finished: 0 run (0:00:01.9803681) ==========

It doesn't seem to be discovering either of the tests I'd written, and I'm not sure why.

Amory answered 7/5, 2018 at 20:41 Comment(7)
It seems you should add RUN_ALL_TESTS into your main. See the example github.com/google/googletest/blob/master/googletest/docs/…Konyn
You should not include *.cpp files as in: #include "../ConsoleApplication1/ConsoleApplication1.cpp. Second, to be able to use gtest, you need to include it (is it included in "pch.h"?). And third, gtest has a particular way to be initialized and executed. Look at the docsOpinionative
@Konyn This was all I needed!Amory
@Opinionative Looks like it was just the initialization that I was missing. Gtest is included from pch.h Why is including #.cpp a bad practice?Amory
@NeilRuggiero I'll not get into details, but you can look here, for example: #1686704 By the way, why is gtest.h buried in pch.h?Opinionative
@Opinionative Thanks for the link, much appreciated! I'm not exactly sure why gtest.h is included from pch.h, that was the way the project was set up using the built in Visual Studio toolAmory
@NeilRuggiero pch means "Precompiled Header". That file is optional. You can include gtest.h directly, delete pch.h and deactivate precompiled headers in the compiler options, i.e. in the project properties under Configuration Properties --> C/C++ --> Precompiled Headers.Frenchify
K
10

GoogleTest framework in the common case requires RUN_ALL_TESTS macro in main:

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

Then you can add your tests into different cpp files and the magic under the hood will launch all of them and show nice report.

Although, you can use Google Tests even without this macro. See this answer.

Konyn answered 7/5, 2018 at 20:52 Comment(8)
Thanks so much, this fixes my issue. Accepting your answer.Amory
That link is deadFeudist
I have the same issue. Where should RUN_ALL_TESTS be added? In the test.cpp or ConsoleApplication1.cpp?Gilleod
@Hamid, in test.cpp. There is no main function in library, if you're going to test it.Konyn
@Konyn I have the same problem. However, if I add the main function in the test project it complains that main has been defined twice. This is obviuosly the case since I already have a main function in my main.cpp (part of the actual project). In that project the test framework is not included (so I don't have access to the the headers to include it there) Help please?Yuletide
@AdrianKoch, it seems like you link the main project to the test project. The purpose of gmock and unit testing overall is to test separate classes. What you should do is to compile implementations of your classes (without your project entry point) and link to gmock.Konyn
@Konyn Ok that makes a lot of sense. So for a c style project that only contains functions and structs I would have my functions in a separate file and only include that file to the test project?Yuletide
@AdrianKoch, plain C code cannot be mocked with gmock out of the box. However, there are some tricks you can do. Take a look at this question #31989540Konyn
F
2

The answer about RUN_ALL_TESTS() in main() is close, yet there are details. Have currently discovery working without manual main.

Worth a note that setting Project Configuration -> Referenced Packages -> Google test -> Use Google Test's main Function is supposed to provide main automatically.

It may be useful to enable debug under Tools -> Options -> Test Adapter for Google Test -> General -> Print Debug Info.

After enabling, had additional entries in the log:

Found 4 test method symbols and 0 trait symbols in binary  ...  
Found 0 tests in executable ...  
Test discovery completed ...  
No test is available in ...  

An actual problem was including wildcard *\*.obj in Additional Dependencies (with intention of avoiding of adding each .obj manually). This also included obj with main() from referenced project, which somehow replaced the intended by GT alternative.
Removing excessive *.obj solved the problem.

Flak answered 14/10, 2023 at 0:24 Comment(0)
R
1

I know this thread is quite old, but I found another potential cause for this error. In my case, the test exe file could not load a DLL, and terminated without providing the test listing. I changed the test unit's output directory in the project settings to be the same as the DLL, and the tests worked fine after that.

Restrictive answered 18/8, 2022 at 15:45 Comment(0)
P
0

@NuPagadi have right with his answer. If you after that still have problems, use right google test nuget. I have same code, I just switch from dyn.rt-dyn to static.rt-dyn and test explorer find all tests.

Pediment answered 5/11, 2020 at 14:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.