TK.
TK.

Reputation: 47873

Automatic Unit Testing with NANT and VS2008 during build process

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?

Upvotes: 3

Views: 974

Answers (2)

Michael Lloyd Lee mlk
Michael Lloyd Lee mlk

Reputation: 14661

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

(Correct for an old version of NAnt but apparently not any more. See the accepted answer).

<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

Upvotes: 0

TK.
TK.

Reputation: 47873

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.

Upvotes: 2

Related Questions