This is the next in a series of videos on how to use VS2012 and Google Test. The typical "Ctlr-F5" in VS2012 will bring up and run the unit level tests for the project. But that can be hard to filter through all of the tests that are run. Especially when you are running hundreds or thousands of tests in your project.
This video will show you how to run unit level tests in the VS2012 using a gtest addin. It will show also how to run unit level tests from the command line.
The video covers the following items.
- Adding the Google Test Add-in
- Run Tests(All, Selected, Failed)
- Debugging Tests
- Running from the command line
- Integrating into CI
Once you have install this you will need to restart visual studio.
Now you will see a new menu item TEST. Select TEST and you can see many options for you, including Run All, Run Selected, and Run Failed. This plug in makes it much easier to work with your tests and your code. You can also debug your tests with this plugin. Just select the Debug Test options in the TEST menu.
Integrating your Unit Level Tests into you build or continuous integration system requires running the tests from the command line. Google Test has that ability as well. But you will need to write your own main program. First create a main.cpp file and put the following code in the file:
int
main(int argc,
char** argv)
{
// This allows the user to override the flag on the command line.
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
It is important to include the ::testing::InitGoogleTest call as it sets up the options for running the tests. This allows us to pass command line arguments to the executable.Some of the most common arguments are:// This allows the user to override the flag on the command line.
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
- --gtest_filter=* - Runs all the tests
- --gtest_filter=BitcoinTransaction.* - Only run the BitcoinTransaction tests
- --gtest_repeat=1000 – Repeat tests 1000 times
- --gtest_repeat=-1 – Run forever
- -- gtest_output=xml – Great for CI that can parse junit
- --help - list all of the options for running test commands.
Hope this helps with the velocity and quality of your product development. Check out my next videos that will discuss architecting tests and using test mocks.
DWP