I'm relatively new to C++ and visual studio and I have a couple of questions regarding the best/most efficient way to set up unit tests using the unit test framework that is included in Visual Studio 2015 Community Edition.
Lets say this is the structure of my program-
Solution 'Project1'
References
External Dependencies
Header Files
Resource Files
Source Files
Source.cpp
UnitTest1
References
Project1
External Dependencies
Header Files
Resource Files
Source Files
unittest1.cpp
The source.cpp just includes a main method and a couple other methods to just keep a basic example. unittest1.cpp just contains a single
Assert::AreEqual(some number, result of some function from source.cpp);
In order to be able to build the unit test I had to change the properties of 'Project1' to be a static library (.lib). Then I had to list Project1 as a reference for 'UnitTest1'. Then I had to edit the configuration of the linker for 'UnitTest1' so that the directory where Project1.lib is build is added to 'Additional Library Directories', and also add Project1.lib in 'Additional Dependencies' in configuration->linker->input.
I suppose I can stomach doing this every time but then once you build the solution, if I want to build 'Project1' as a .exe again I would have to undo all those changes in order to successfully build the solution again.
I'm wondering what's the best way to set up all this configuration so that a person can have a basic unit testing capability while they continue to develop their project? Seems like there's got to be a better way but many of the tutorials I looked at included the steps I mentioned above. To reiterate, I'm just using the unit testing framework that comes packaged with Visual Studio Community edition. I'm open to the use of 3rd party tools that might simplify this process.
Aucun commentaire:
Enregistrer un commentaire