How to use catch2 for testing a big project in Visual Studio

609 Views Asked by At

I have a big project in Visual Studio 2019.
And I want to test it by Catch2 library.

I'd like to know how to include this library correctly in my project?

For example, in main.cpp I do:

#include <header1>
#include <header2>
#define CATCH_CONFIG_MAIN
#include <catch/catch.hpp> // header only library

void function_1()
{
   // do something
}

void function_2()
{
   // do something
}

// int main()
// {
TEST_CASE("My test number 1", "[Test1]")
{
   function_1();
   function_2();

}
// return 0;
// }

After that I get a lot of errors like

main.obj : error LNK2001: unresolved external symbol "public: __cdecl Catch::AutoReg::AutoReg(struct Catch::ITestInvoker *,struct Catch::SourceLineInfo const &,class Catch::StringRef const &,struct Catch::NameAndTags const &)" (??0AutoReg@Catch@@QEAA@PEAUITestInvoker@1@AEBUSourceLineInfo@1@AEBVStringRef@1@AEBUNameAndTags@1@@Z).

So, how should I write my code correctly to use Catch2 library?

0

There are 0 best solutions below