Problem
In an attempt to launch C++ google tests in Rider or ReSharper, the following error occurs.
Cause
Rider/ReSharper tries to launch the built executable of the project where unit tests are stored. Since the build output of a library project is a .lib file and you can't launch a .lib file on Windows, the error is expected.
Resolution
When a library project contains unit tests, there is probably a Console Application project that references the library and is used for running tests. The command line for running tests should be specified explicitly. Typical code for running tests is as follows:
#include "gtest/gtest.h"
#include "fileWithTestsInLibProject"
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Remark for screenshots: The UnitTests project references gtest framework via "Include Directories", Library Directories, Linker | Input | Additional Dependencies (gtestd.lib, gtest_maind.lib). Also, it references the UnitTests.lib project. The UnitTestsLib project contains all the unit tests.
In Rider it can be done from project properties under Test Runner tab:
In ReSharper the Configuration Properties | Debugging | Command should be adjusted to point to the executable project:
Comments
0 comments
Please sign in to leave a comment.