views:

32

answers:

2

I'm using VS2008 Pro and as such my c# project includes a bunch of Unit Tests written in the MS bundled unit test framework (sorry I have no idea what its official name is!). I would like to be able to run these unit tests as part of my build process.

Is it possible to get Nant to automatically run these Unit tests during a build?

+1  A: 

It is calld MSTest. You could just use the exec task to call the executable directly:

<exec>
    <executable>%VS_INSTALL%\Common7\IDE\MSTest.exe</executable>
    <baseDirectory>PPRJECT LOCATION</baseDirectory>
    <buildArgs>/testcontainer:TestDLLs /runconfig:localtestrun.Testrunconfig /resultsfile:testResults.trx</buildArgs>
    <buildTimeoutSeconds>600</buildTimeoutSeconds>
</exec>

I am surprised it does not come with a task built in.

For reference here is a list of MSTest Command-Line options.

NB: these options are for VS2010, it is possible to view the Command-Line options from other VS versions by selecting the correct version on the page

mlk
Nant seems quite dead now, ms tests were not popular when it was still being developed.
Grzenio
I disagree, when the last update to nant was 2 days ago (August 17, 2010). I don't think you can really say its 'dead'!
TK
A: 

The solution that worked for me is the following:

<exec program ="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe" >
    <arg value="/testcontainer:${Test_dll}"/>
    <arg value="/resultsfile:C:\Test\TestResults.trx"/>
</exec>

This is just the basic nant element, although it is as extensible as the MSTest command line will allow.

TK