So, this seemed basic, but no one appears to have written about it on the web.
You are in Unmanaged C++ solution in VS. You want a project, and then you want a second project that tests the first project.
Well, the test project will never be able to Link to the object files of the main project. Try it. The linker will complain.
The testing project needs its own copy of the main project’s .obj files.
1. Add every single file from the main project to the test project.
That’s right, you can’t just put the main project’s obj files in the test projects lib path. If you try to force it to link, it will crap out from duplicate symbols in the linker.
So, for each file in the main project, you need to click ‘Add > Existing Items” in the test project.
I made a separate folder in Visual Studio for my actual Testing files, so they wouldn’t get confusing. Note, folders in visual studio are not created on the windows explorer file system. They exist only in the view provided inside visual studio.
So, now there are 2 copies of every .obj file in the main project, one in each project’s intermediate directory. However, there is still only one of each source .cpp and .hpp file. This is shared between the two projects, but these source files should reside in the main projects directory, not the test directory.
Personally, I’d like to be able to make the test project have Read-Only references to the main projects source files. Just so that I never accidentally edit the main project from th e source project. but oh well.
I suppose this makes sense, but I sure as hell never saw mention of this in any of the tutorials for creating unit tests for unmanaged c++ in Visual Studio.
Well, there went another 3 hours of my life to creating a proper build environment for c++. Wish I had 3 hours of unit testing instead.
If you’re reading this, hope it helps.