Linker error while unit testing with Visual Studio C++

后端 未结 3 1320
花落未央
花落未央 2021-01-14 06:23

I want to unit test my C++ project with Visual Studio. After adding the folders from my project as include path to my test project, I get linker errors when trying to compil

3条回答
  •  难免孤独
    2021-01-14 07:15

    I believe the chosen answer is not correct. Tests typically should be run in their environment; therefore, they should not access the implementation (.cpp)


    When you create a separate Test Project on Visual Studio (VS 2017) you need to create a reference to the project you want to test (right-click test project -> Add -> Reference -> tick projects): Add a reference

    If you see some linker errors, right-click from the Unit test project: Project->Linker->Input->Additional Dependencies->Edit then add the path to your .obj files. You could try something like "$(SolutionDir)ConsoleApplication1\$(IntDir)*.obj" where ConsoleApplication1 is the target project name.

    Path to .obj

    Initially, I only wanted to put a comment on Cornelis' post, but I couldn't.

提交回复
热议问题