Tuesday, October 29, 2013

VS2012 & Google Test - Running Unit Level Tests - Video #3

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.
  1. Adding the Google Test Add-in
  2. Run Tests(All, Selected, Failed)
  3. Debugging Tests
  4. Running from the command line
  5. Integrating into CI



First we need to download and install the visual studio google test add-in. It can be found at http://visualstudiogallery.msdn.microsoft.com/f00c0f72-ac71-4c80-bf8b-6fe381548031/file/87766/3/GoogleTestAdapter.vsix.
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:

  • --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




No comments:

Post a Comment