


Assuming you connected your test project to your project(s) under test via Add > Reference earlier, you can simply add the #include statements for the header files of the code you want to test. Right from the start, you’ll notice that dependencies have already been set up to the test framework, so you can get to work writing your tests. Open unittest1.cpp in your test project and look at the starting code provided: If you followed the steps in the previous procedure, you should have a unit test project set up along with your main code. The framework defines a series of macros to provide simplified syntax. Visual Studio ships with a native C++ test framework that you can use to write your unit tests. The Microsoft Native C++ Unit Test Framework To unit test private functions, you must write your unit tests in the same class as the code that is being tested. NOTE: You will only be able to unit test public functions this way. You can now start writing tests, as long as you add #include statements for the headers you want to access. Your unit testing project can now access your project(s) under test.

Check any projects that you want to unit test from your test project, and then press OK.Right-click the unit test project and choose Add > Reference… The next thing to do is to add references to any projects that will be tested. Visual Studio will create a new project containing unit tests, with all dependencies to the native test framework already set up.Select Native Unit Test Project, give the project a descriptive name, and then click OK. Click the Visual C++ category, and choose the Test sub-category.

