I'm new to unit testing in C++ and want to get some advice on this. I use Visual Studio 2019 for development and I chose Catch2 as my testing library, I also got the Test Adapter for Catch2 installed.
I read docs for both Catch2 and Test Adapter for Catch2 on GitHub, but I still cannot figure out a proper way to use unit test in Visual Studio.
Let's assume that I already have a project with some classes in it and I want to test those classes. Should I put files with test code in the same project or should I create new test projects within the solution?
When I try the first approach, Test Explorer doesn't discover tests unless I comment out the main() function of the project. With second approach, I get a bunch of unresolved external symbol errors for my classes' methods, although I set correct relative paths to header files and referenced the main project from the test project:
LNK2019 unresolved external symbol "public: bool __thiscall MyClass::Check(int,int)" (?Check@MyClass@@QAE_NHH@Z) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____0(void)" (?____C_A_T_C_H____T_E_S_T____0@@YAXXZ)
I would appreciate if someone show me a correct way to do unit testing with Catch2 in VS.