MSTest task for MSBuild

 

I was looking for an ability to run automated tests from MSBuild, my demands are:

1) Be able to run tests from many solutions (that contains many projects and many tests).

2) Be able to control the entire test running definition from one file(and not to open each proj file to add a new test every time someone in my team writes one).

3) Be able to separate sets of tests that take more time to run from those that run with no time – usually it will be divided into unit and integration tests.

4) Do all this without using .vsmdi file – because from some reason this file not work properly within TFS source safe, which me and my team are using.

MSBuild have no task for running units. Those are the alternatives I found for units to run from MSBuild.

1) Run the MSTest command directly,by using exec task, like this

<Exec Command='"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\mstest.exe" /testcontainer:c:\projects\MyTests\Sampe.Tests.dll />

This solution is pretty good if you have one test project to run, if you have more than one you have to specify the "/testcontainer:…" parameter for every project that you want to run. Or add new exec task.

If you have to run it for, let say five solutions, when each one contains more the one test project, you have already ten projects that you have to maintain, and I don’t want to be the one that doing this.

2) Running TestToolsTask task which comes with TFS and can be found in Microsoft.TeamFoundation.Build.targets file.

This one can be used only with .vsmdi files, and this differing number four in my demands.

3) Writing task of my own, and make all my dreams come true. And this is what I did.

The task has all the functionality that MSTest command line tool has.

How to use the task?

Import the task in you .proj file:

<UsingTask TaskName="Dobkin.Common.Tasks.MSTest"AssemblyFile="D:\MyFolder\Dobkin.Common.Tasks.dll"/>

And call the task:

<ItemGroup Condition="$(ProjectName) == 'Project1'">

        <Tests Include="c:\Project1\Project1.BL.Test.dll"/>

        <Test Include="c:\Project1\Project1.Dal.Tests.dll"/>

</ItemGroup>

 <ItemGroup Condition="$(ProjectName) == 'Project2'">

        <Tests Include="c:\Project2\Project2.BL.Test.dll"/>

        <Test Include="c:\Project2\Project2.Dal.Tests.dll"/>

        <Test Include="c:\Project2\Project2.Utils.Tests.dll"/>

</ItemGroup>

And that’s it. For now on, every new test project or even a whole new solution, you will add, you have to change only this file (for new solution of course you have to import this file first)

Documentation of how to use the task is included in the attachment.

MSTest.rar

Published Sunday, December 16, 2007 12:25 AM by Nati Dobkin

Comments

# re: MSTest task for MSBuild@ Sunday, December 16, 2007 8:09 AM

putting the path to an assembly in an MSBuild file is considerd a bad practice since it will work only on your machine.

Having a relative path or registering it in the gac( which I don't like also) will work.

# re: MSTest task for MSBuild@ Sunday, December 16, 2007 8:31 PM

I am totally agreed with Yossi. The example that I showed is for proof of concept only. Defiantly the best practice is to write relative path to you working directory.

Thanks Yossi for the correction.

# re: MSTest task for MSBuild@ Friday, April 24, 2009 7:05 PM

I don’t see any <Target> tags. So how does it execute task?

by Mladen Trifunovic

# Scott&#8217;s Blog &raquo; Blog Archive &raquo; Calling MSTest from MSBuild or The Price of Not Buying TFS@ Wednesday, June 03, 2009 5:56 PM

Pingback from  Scott&#8217;s Blog  &raquo; Blog Archive   &raquo; Calling MSTest from MSBuild or The Price of Not Buying TFS

# MSTest task for MSBuild | LieberLieber Software TeamBlog@ Friday, September 18, 2009 4:59 PM

Pingback from  MSTest task for MSBuild | LieberLieber Software TeamBlog

# Wenger Impulse Computer Bag, Isuzu Impulse Used Camshaft@ Friday, May 21, 2010 11:08 PM

Pingback from  Wenger Impulse Computer Bag, Isuzu Impulse Used Camshaft

# 535i Telekom, 535is Ground Clearance 2010 Bmw 5 Series@ Saturday, May 22, 2010 5:11 AM

Pingback from  535i Telekom, 535is Ground Clearance 2010 Bmw 5 Series

# 760li Promo New Bmw, How To Unlock W760 Guide@ Saturday, May 22, 2010 8:54 AM

Pingback from  760li Promo New Bmw, How To Unlock W760 Guide

# 500sl 6.0, Buy 500sl Accessories New Mercedes - 356.jeepsunlimted.com@ Tuesday, May 25, 2010 11:46 PM

Pingback from  500sl 6.0, Buy 500sl Accessories New Mercedes - 356.jeepsunlimted.com

# Used Dump Trailers For Sale, Honda Crv Nissan Xtrail - 345.unlockiphone30.net@ Wednesday, May 26, 2010 3:38 AM

Pingback from  Used Dump Trailers For Sale, Honda Crv Nissan Xtrail - 345.unlockiphone30.net

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: