google / google/googletest

gtest_main does not discover any tests on Windows (Visual Studio)

Open
#2,157 15 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

I am using googletest in my project without problems on Linux (Ubuntu 16.04, 18.04) and Mac.
Now porting the same source to Windows (Visual Studio 15 2017), my googletest binary doesn't find any tests:
```
Running main() from gtest_main.cc
[==========] Running 0 tests from 0 test cases.
[==========] 0 tests from 0 test cases ran. (1 ms total)
[ PASSED ] 0 tests.
```
(same if I link in gmock_main instead of gtest_main).
Now, if I compile in a separate main.cpp:
```
#include
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
```
instead of the one provided in gtest_main or gmock_main libraries everything works.

I'm using CMake to build my project, and I don't set any googletest specific settings except
``` -DGTEST_LINKED_AS_SHARED_LIBRARY```

Tested with versions master branch versions 98a0d00 and efecb0b

Contributor guide

Open the contributing guide

Research direction

Start by comparing gtest_main.cc and gmock_main with the working standalone main.cpp, then inspect the CMake configuration using GTEST_LINKED_AS_SHARED_LIBRARY on Visual Studio. Reproduce the issue with the reported commits and verify that the Windows-built test binary discovers and runs the registered tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.