Path of least resistance when unit testing C++ code in an exe, in Visual Studio 2012

前端 未结 3 882
挽巷
挽巷 2021-02-20 12:33

I\'m in need of some sage advice here. Long story short, I\'m rebuilding a - for me - relatively complex app comprised of about 7000 lines of code. I ran into a number of issues

3条回答
  •  孤街浪徒
    2021-02-20 13:06

    This will depend on how you have your solution structured. The way I like to structure my solutions is to have three projects.

    • A .lib project that has my source code in it.
    • An executable project, linked with the .lib. This calls into the .lib in the main() call
    • A test project (exe), linked with the .lib.

    With this structure you can use the Add New Reference... button in the Common Properties section and the references will be sorted for you (except the header include path found in C++\General\Additional include directories).

    If you do not want to restructure your projects you can tell the linker about each obj file (Linker\Input\Additional dependencies). This may be a significant number of .obj files if you have a lot of classes that you want to test. Unfortunately, you may have issues if you use pre-compiled headers.

    I would suggest restructuring the projects if you can.

提交回复
热议问题