DCSIMG
MSTest task for MSBuild - Nati Dobkin
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

# re: MSTest task for MSBuild@ Thursday, September 09, 2010 11:00 AM

I don't know if you've heard of <a href=www.varollo.com/.../a> yet, but it is a way to make money by watching commercials online. It is invite only so I'm extending my invitation to everyone that wants to take advantage the new advertising method that Varolo is offering and to make some extra cash. If you visit Varolo, you can see their video on more of what I'm talking about, how it works and the potential you have to make some decent money. Don't take my word for it, check it out for yourself.

Thanks,

-J

# zkawalec@FP@ Friday, December 10, 2010 1:22 PM

Pingback from  zkawalec@FP

# re: MSTest task for MSBuild@ Friday, February 25, 2011 10:10 PM

ThePigsSayMoo|Well, she only saved him coz Draco was alive.....and Harry did save his life twice that night.п»ї

 http://selectworld.net/?p=347

thplousaqq

by ToratordDrale

# re: MSTest task for MSBuild@ Thursday, May 05, 2011 9:00 PM

How about removing the spam comments?

by Anon

# re: MSTest task for MSBuild@ Tuesday, July 10, 2012 3:59 PM

while running test using first option i got below warning

Warning: Test Run deployment issue: The assembly or module 'msshrtmi' directly or indirectly referenced by the test container 'e:\source\taf\user management\test\bin\debug\saras.usermanagement.test.dll' was not found.

what to do.

by meraj

# re: MSTest task for MSBuild@ Wednesday, July 18, 2012 12:27 PM

you can always count on search results marketing when you would along the lines of to promote products online.

by Flores

# re: MSTest task for MSBuild@ Monday, July 30, 2012 8:17 PM

seafoods have been great because that they are really

tasty, i think that almost all seafoods have been super duper

tasty

# re: MSTest task for MSBuild@ Tuesday, July 31, 2012 9:30 PM

i use google when i would for instance to do some spanish translation, its first-rate for wide-ranging spanish

translation

by Matlock

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 6:27 AM

You have brought up a very first-class points , appreciate it for the post.

by Lau

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 6:40 AM

I always visit new blog everyday and i found your blog.

,‘

by East

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 6:58 AM

I gotta favorite this internet site it seems very helpful very helpful

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 7:07 AM

His idyllic existence is one day broken when a team of heavily armed

men turn his house into dust in an attempt to kill him, it is up to

him then and a few old friends to use and figure out to that the bottom of that the unknown

kill squad.

by Petit

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 7:14 AM

Do you write more It merely required a few moments to see your entry and

so have an awareness that I recognize most people miss out on.

Getting more people to join that the discussion is typically a great thing.

by Kidd

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 7:16 AM

I actually love the method you discuss this kind of topic.

by Freed

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 10:26 PM

Thank you for your content very helpful for me,

an alternative webpage I found and hope you like it

by Waldron

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 10:32 PM

You need to take part in a tournament for starters of that the finest domains on-line.

Ill recommend this blog!

by Ferrell

# re: MSTest task for MSBuild@ Saturday, August 11, 2012 11:18 PM

I am pleased, I have to state. Actually not often

will i come across your blog that is certainly every educative as well as enjoyable, and let me tell you, you have got strike that the actual toenail about the head.

That the idea will be exceptional the difficulty is something that doesnt sufficient folks are speaking wisely about.

I am extremely comfortable which i stumbled all through

this kind of in my search for a very important factor relating to this.

by Duckett

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 1:29 AM

I was just browsing for related blog posts for my project research and I happened to get yours.

Thanks for the useful info!

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 1:40 AM

You commit an error. Write to me in PM, we will discuss.

by Gerald

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 1:50 AM

Just where maybe you have discovered that the source intended for this post Great studying I have subscribed for your blog feed.

by Neely

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 5:09 PM

i am using infolinks and chitika and i think infolinks have

that the best payout .

by Prater

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 5:13 PM

Sometimes the easier to only take one step back again and also know

that few people gives your beliefs

by Culp

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 5:30 PM

This one page has a tendency to redeem much page views.

Exactly how do you market it

by Graf

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 6:20 PM

Spot on with this writeup, I really suppose

this website needs far more consideration. Ill most likely be once more to

read much more, thanks for the information.

by Krebs

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 8:16 PM

I appreciate your time and effort allocated to this article, bad i had to spend this long

to search out it on that the other hand because that they say top quality is difficult to get.

Continue the first-class work.

by Maynard

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 9:08 PM

“Hello, you site is very funny he told me to cheer up

# re: MSTest task for MSBuild@ Sunday, August 12, 2012 10:55 PM

most broadband services have been crappy, that they cant maintain high data transfer rates

# re: MSTest task for MSBuild@ Monday, August 13, 2012 3:32 AM

This web site is my intake, very first-class style and Perfect articles.

# re: MSTest task for MSBuild@ Wednesday, August 15, 2012 3:52 PM

This sort of thing needs to happen! Simply letting the quota happen isnt acceptable.

This will help you stay above that the curve.

# re: MSTest task for MSBuild@ Friday, August 24, 2012 5:15 PM

Okegreat to seek out out, there were without a doubt a number of points that I hadnt thought

of before.

by Wirth

# re: MSTest task for MSBuild@ Saturday, August 25, 2012 11:01 PM

Loving the info on this website, you have done outstanding job on the blog

posts.

by Ambrose

# re: MSTest task for MSBuild@ Friday, August 31, 2012 7:01 AM

lip gloss with olive oil is the best because it can moisturize your lips as well,

.

by Noble

# re: MSTest task for MSBuild@ Saturday, September 01, 2012 1:59 AM

Is there a toughest thing in that the world To believe.

by Sikes

# re: MSTest task for MSBuild@ Saturday, September 01, 2012 6:04 AM

bar stools that are made from stainless steel have been

that the best as they dont tarnish often

# re: MSTest task for MSBuild@ Saturday, September 01, 2012 9:03 PM

bed sheets that have been made of flannel fabric

are the best type of bed sheets

# re: MSTest task for MSBuild@ Tuesday, September 04, 2012 12:33 PM

i can see tons of free music online but most of them are pirated.

by Omalley

# re: MSTest task for MSBuild@ Tuesday, September 04, 2012 12:50 PM

divorce is of course one of the worst thing someone to could experience then again

you could find out over it

# re: MSTest task for MSBuild@ Tuesday, September 04, 2012 2:04 PM

i would love to munch so a whole lot of italian foods, italian foods are that the

best in my opinion and they are very tasty.,

by Amato

# re: MSTest task for MSBuild@ Tuesday, September 04, 2012 2:23 PM

Hello! Do you know if they make any other plugins to safeguard against hackers Im kinda paranoid about losing everything Ive worked hard on.

Any tips

by Ault

# re: MSTest task for MSBuild@ Tuesday, September 04, 2012 2:45 PM

LCD TVs can actually save you from high electricity bills and office space

by Collier

# re: MSTest task for MSBuild@ Wednesday, September 05, 2012 9:08 PM

Thanks for that the great post on your blog, it actually gives me an insight

on this topic.

by Eubanks

# re: MSTest task for MSBuild@ Wednesday, September 05, 2012 11:46 PM

Hi, do you have a facebook fan page for the blog

by Paige

# re: MSTest task for MSBuild@ Thursday, September 06, 2012 12:31 AM

You need to join in a contest along the lines of of the greatest domains via

the internet. Ill suggest this blog!

by Willett

# re: MSTest task for MSBuild@ Thursday, September 06, 2012 10:24 AM

There are pros and cons to taking this approach. However you

possibly can make the child custody hearing work to your advantage by knowing what the court expects out of

you because a parent.

by Machado

# re: MSTest task for MSBuild@ Thursday, September 06, 2012 10:26 AM

Remarkable page! I seriously had our checking.

Im hoping to read effortless things a large amount more on your side.

In my opinion that you have exceptional awareness

and even prospect. Now i am quite pleased within this guidance.

by Sherrod

# re: MSTest task for MSBuild@ Monday, September 17, 2012 2:29 PM

When I originally commented I clicked that the Notify me when new surveys have been added

checkbox and after this each time a comment is added I determine

four emails concentrating on that the same comment.

Is there in any means you are able to eliminate me out

of that service Thanks!

by Gann

# re: MSTest task for MSBuild@ Wednesday, September 19, 2012 6:04 PM

I was reading through some of your blog posts on this site and I think this web site is really instructive!

Keep on putting up.

# re: MSTest task for MSBuild@ Wednesday, September 19, 2012 6:12 PM

This site is actually a walkthrough it is

that the details you wanted about it and didnt be acquainted with who to question.

Glimpse here, and youll certainly find it.

by Spinks

# re: MSTest task for MSBuild@ Friday, September 21, 2012 12:53 PM

seafoods are great as they are actually tasty, i

think that almost all seafoods have been super duper tasty

by Ritter

# re: MSTest task for MSBuild@ Friday, September 21, 2012 2:46 PM

Well, Objective, im not so i are in agreement with all in

this article, however you do make a important comprehension with this issue.

I may instruct myself

by Oconner

# re: MSTest task for MSBuild@ Friday, September 21, 2012 5:19 PM

I Love LENKA and i always play her music on my iPod. her music is sort of unique:

:

by Conn

# re: MSTest task for MSBuild@ Friday, September 21, 2012 6:21 PM

That the climax by far has the best parts of the film.

# re: MSTest task for MSBuild@ Friday, September 21, 2012 7:27 PM

Tremendous guide! Make took pleasure in the exact looking at.

I hope to find out much out of your company. My wife and i you

might incredible knowledge together with view.

What i’m particularly fascinated in this area material.

by Lumpkin

# re: MSTest task for MSBuild@ Friday, September 21, 2012 7:36 PM

Thank you for sharing your stuff on blog. it’s probably that we have similar interests.

something are very useful to me.

# re: MSTest task for MSBuild@ Friday, September 21, 2012 8:25 PM

my dad is really a massage therapist and he can really

relieve small pains and injuries“

by Benson

# re: MSTest task for MSBuild@ Friday, September 21, 2012 11:58 PM

Votre étude alors voilà quelques satisfaisants sujets de discussion cependant reste sceptique de la

sincérité de vos taux affichés ici dans ce petit paragraphe

by Woodley

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 3:41 AM

I really love the line of attack you discuss this kind of topic.

by Matias

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 4:18 AM

Which is some inspirational stuff. Never knew that opinions could be this varied.

Thanks for every one of the enthusiasm to supply

such tips here.

by Gilmer

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 4:55 AM

I tried to submit a comment earlier, although it has not shown up.

I think your spam filter may possibly be broken

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 5:09 AM

well of course, everyone loves to discover rich

then again not everyone would love to do challenging

work

by Brandon

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 1:27 PM

Awesome! I thank you your contribution to this matter.

It has been insightful. my blog maple syrup

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 1:37 PM

Thanks for taking the time to post this data. I am recently one of your most

passoniate followers. I have your RSS feed in my iphone

and will check back regularly.

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 2:39 PM

Very significant info!Perfect just what I was searching for!

. “Success is that old ABC — ability, breaks, and courage.

by Charles Luckman.

by Roberts

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 4:18 PM

divorce is of course one of that the worst thing someone to could experience on that the other hand you could determine over it

by Holly

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 5:12 PM

This was really a fascinating matter, I am very lucky to have the ability to come to your blog and I will

bookmark this page so that I might come back

one other time.

by Batson

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 5:21 PM

Nearly the whole thing seems to jump off

the screen, however at the same time that the film doesnt actually have any other standout moments where the

effect is utilized in a system that actually wows it's audience.

by Mitchel

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 5:50 PM

MrNewbieVideo New News With Five New Apps, Zoho Is Now That the

Largest Developer On The Google Apps Mar

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 6:06 PM

I am pleased that I detected this web site, precisely the right information that I was looking for!

.

by Avery

# re: MSTest task for MSBuild@ Saturday, September 22, 2012 6:10 PM

Some genuinely great information , Glad I discovered this.

# re: MSTest task for MSBuild@ Tuesday, September 25, 2012 2:43 PM

Wonderful I enjoyed seeking through your page.

I think you are truely remarkable.

by Elkins

# re: MSTest task for MSBuild@ Saturday, September 29, 2012 4:30 PM

not everyone would need a nose job conversely my girlfriend actually needs some rhinoplasty coz her nose is quite crooked.

,

by Corey

# re: MSTest task for MSBuild@ Tuesday, November 13, 2012 10:11 PM

This is a wonderful internet page, could you be interested in performing an interview about just how you designed it? If so e-mail me!

shoes skydrive.live.com/redir!110

# re: MSTest task for MSBuild@ Monday, November 26, 2012 11:06 AM

I will tell your friends to visit this site. .Thanks for the

article.

# re: MSTest task for MSBuild@ Wednesday, November 28, 2012 5:04 PM

I notice there is certainly quite a large amount of spam on this

blog. Do you may need help cleaning them up? I might help between courses!

by Ferro

# re: MSTest task for MSBuild@ Thursday, November 29, 2012 10:11 AM

Someone Sometimes with visits your site regularly and recommended it

to me to read as well. The system of writing

is great and the content is top-notch. Thanks for the insight you give out

the readers!

by Bailey

# re: MSTest task for MSBuild@ Wednesday, December 12, 2012 9:17 AM

Actually there is a better way to do this and that is by using batching.

Example:

<?xml version="1.0" encoding="utf-8" ?>

<Project xmlns="schemas.microsoft.com/.../2003">

 <PropertyGroup>

   <MSTestExePath Condition="'$(MSTestExePath)'==''">&quot;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe&quot;</MSTestExePath>

 </PropertyGroup>

 <ItemGroup>

   <TestAssemblies Include="..\..\..\Main\bin\*.Tests.Unit.dll"/>

 </ItemGroup>

 <Target Name="unittest">

   <!-- Call CheckOneAssemblyFile foreach file in TestAssemblies -->

   <MSBuild Projects="$(MSBuildProjectFile)"

     Properties="CurrAssemblyFile=%(TestAssemblies.FileName);CurrAssemblyFullPath=%(TestAssemblies.FullPath);MsTestPath=$(MSTestExePath)"

     Targets="CheckOneAssemblyFile">

   </MSBuild>

 </Target>

 <!-- This target checks the current analyzed file $(CurrAssemblyFile) -->

 <Target Name="CheckOneAssemblyFile">

   <PropertyGroup>

     <TestAssembliesName>"$(CurrAssemblyFile.Replace(".Tests.Unit",""))"</TestAssembliesName>

   </PropertyGroup>

   <Message Text="Current Assembly File: $(CurrAssemblyFile)"/>

   <Message Text="Current Assembly Full Path: $(CurrAssemblyFullPath)"/>

   <Message Text="Current Module to be tested: $(TestAssembliesName)"/>

   <Exec Command='$(MsTestPath) /testcontainer:"$(CurrAssemblyFullPath)"'/>

 </Target>

</Project>

by Ray

# re: MSTest task for MSBuild@ Tuesday, December 25, 2012 11:04 AM

i have seen several cellular browsers and used some of them, they

have been still a bit slow;;

by Liles

# re: MSTest task for MSBuild@ Saturday, February 09, 2013 1:06 AM

What a lovely blog page. I will definitely be back again.

Please keep writing!

by Gerber

# re: MSTest task for MSBuild@ Friday, May 31, 2013 3:54 AM

I visited various websites but the audio quality for audio songs present at this site is really fabulous.

Leave a Comment

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

Enter the numbers above: