I'm currently evaluating unit testing frameworks for our dev team and hit a problem I can't figure out how to solve.
Our application is build using Visual Studio 2017. The solution contains 17 projects. Most of them developed by another team (basically 3rd party library from our viewpoint) and most projects produce a dll file. One project is configured to build the executable.
It's that exe project that I can't seem to test. I've tried both Boost::Test and Google.Test. When i try to write tests using a class defined in one of the dll projects, it works as expected.
But when I try to test code from the exe project, I get LNK2019 "Unresolved external symbol" linker errors for the code defined in the exe project. The include directories are set correctly, the test project references the relevant other projects. I'm at a loss.
After some online search and tinkering with newly set up test solutions I identified two possible causes:
Could my linker error be caused by this? And if so how do I resolve the error?
You cannot (directly) unit test a project that produces an executable file. The unit test framework needs to create an executable to run (and evaluate) the unit tests, so you would end up with two main()s in the project...
I can only suggest the following: Convert the executable project into a library project (no matter if it is a .dll or static library) and move the (hopefully) tiny bit of code that is in the main() to another project which will link the (now library) project into an executable. If your main() has a lot of code, you may consider turning it into a static function, and then invoke that static function (and thus launch your application) from the "new" main() in the "new" executable project.
Then you can test your project like any other "library" project, and have no relevant code to test in your bare-bones executable project.