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.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:
mstest.exe /testmetadata:C:\WORK\WebAii\WebUI_Tests\WebUI_Tests.vsmdi
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
Enjoy!
Elena, Telerik