Telerik blogs

Introduction

Let’s start with a few words about MSTest and MSBuild.

MSTest is a software unit testing framework developed by Microsoft. With MSTest you can manage and run unit tests from within the Visual Studio IDE, as well as externally, from the command line.

MSBuild is a Microsoft build platform typically used in conjunction with Visual Studio. MSBuild version 2.0 is part of .NET Framework 2.0 and works together with Visual Studio 2005. Version 3.5 of MSBuild, which is bundled together with .NET 3.5 (and Visual Studio 2008), allows .NET projects to be built for either 2.0, 3.0 or 3.5 .NET version. This platform helps you create and edit extensible build solutions.

With WebUI Test Studio you can generate a bunch of tests for minutes. If you want to execute them automatically with MSTest some hints follow.

Running the tests with MSTest
You can use MSTest to start tests trough Visual Studio command prompt. A detailed movie how to do this may be found here
(use Ctrl + Mouse Scroll to enlarge the picture in Firefox):

http://www.artoftest.com/community/mstest-Server/CommandLine.aspx

Here is a sample script written in C# that starts a separate process running the tests:

Process p1;
p1 = new Process();
p1.StartInfo.FileName = @"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe";
p1.StartInfo.Arguments = @"/testmetadata:C:\WORK\WebAii\WebUI_Tests\WebUI_Tests.vsmdi /resultsfile:testResults1.trx /noisolation";

p1.Start();

//sends e-mail with the test results
EmailNotification("testResults1.trx", "tests results");
p1.WaitForExit();

 

 

Where:

  • C:\WORK\WebAii\WebUI_Tests\WebUI_Tests.vsmdi – it is a full path of the metadata file which contains information about any tests in a project. You need to specify a full path when use external process to run tests. Otherwise, when the command-line is used – you should navigate to the containing folder (C:\WORK\WebAii\WebUI_Tests) first and then execute the following:
mstest.exe /testmetadata:C:\WORK\WebAii\WebUI_Tests\WebUI_Tests.vsmdi
  • TestResults1.trx file contains the results of the tests execution

 

Running the tests with MSTests can be applied in an MSBuild project.

 

MSBuild Integration

You may use MSbuild to integrate your tests in a build process. MSBuild uses project files to instruct the build engine what to build and how to build it. MSBuild project files are XML files that adhere to the MSBuild XML schema. This is a sample .proj file which runs the same tests mentioned above:

 

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="RunTests"> <Exec Command='"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe" /testmetadata:"C:\WORK\WebAii\WebUI_Tests\WebUI_Tests.vsmdi"' /> </Target> </Project>

I found useful references about MSBuild and MSTest here:

 

http://blogs.msdn.com/biztalk/archive/2008/07/31/msbuild-run-test-cases.aspx

http://blogs.microsoft.co.il/blogs/ndobkin/archive/2007/12/16/mstest-task-for-msbuild.aspx

http://blogs.msdn.com/buckh/archive/2006/11/04/how-to-run-tests-without-test-metadata-files-and-test-lists-vsmdi-files.aspx

 

Enjoy!

 

Elena, Telerik


Comments

Comments are disabled in preview mode.