Integrating Visual Studio unit testing with release management software

Sunday, 13 October 2013 13:32 Stefano Tommesani

AskWatchABS1In a previous post, Unit testing with Visual C++ 2012, the unit testing features of Visual Studio 2012 were shown to be an effective way to improve software quality by introducing various tests. Still, instead of having to run these tests inside the Visual Studio IDE, it would be even better to integrate these tests into a release management software, so that they are automatically performed during each build of the system.

For running these unit tests outside the Visual Studio IDE, from this MSDN page we find out that there are three ways to run them from the command line:


Now that we know how these unit tests can be run without opening Visual Studio, we turn to the release management software. In this example we will use SmartBear's Automated Build Studio, which "easily automates your entire build, deployment, quality assurance and release processes". ABS includes support to all compilers that are included in Microsoft Visual Studio 2012, 2010, Microsoft Visual Studio 2008, Microsoft Visual Studio 2005 and Microsoft Visual Studio .NET 7.x:

Let's start with a Visual C# project: the AskWatch solution contains both the project of main software app (AskWatch) and the project that contains the unit tests (AskWatchUnitTest)


Running the unit tests inside the Visual Studio IDE:


Now that we have a complete solution, hosting both the software code and the unit tests, we can open Automated Build Studio and create a new build process. In this short demo, we will not include some necessary steps for a complete build process, such as checking out code from a SCCM system, e.g. SVN or TFS, or building the installer, as we are only interested on running unit tests during the automated build.

The build process includes 3 steps:

  1. building the unit testing project
  2. running unit tests using MSTest
  3. building the release of the software app

AskWatchABS1Each steps depends on the success of the previous step, so if the build of the unit test project fails, the unit tests will not run, and if the unit tests fail, the final release of the software app will not be built. Even if Microsoft suggest using VSTest.Console instead of MSTest, ABS includes a wizard for MSTest but not for VSTest.Console, so we will keep it easy and use MSTest.

The first step is building the unit test project:


The second step is running the unit tests: select the DLL assembly that contains the units tests in the Debug output directory

AskWatchABS3Finally, if unit tests are successful, we build the main software app using Release settings:


Now it's time to run this macro:


All three steps are completed successfully, and the Log window displays the results of unit tests and warning messages of the C# compiler. This macro is now ready to be integrated into the main release management and run each time an automated build is triggered.

Last Updated on Sunday, 13 October 2013 15:37