This is a sample script that you can include in your build process. Note that the use of the <BuildStep> tasks are optional and you can remove those if you desire.

<Target Name="AfterCompile">
<!-- Create a Custom Build Step -->
<BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Name="NUnitTestStep" Message="Running Nunit Tests">
<Output TaskParameter="Id" PropertyName="NUnitStepId" />

<!-- Get Assemblies to test -->
<TestAssemblies Include="$(OutDir)\**\cs-*.dll" />

<!-- Run NUnit and check the result -->
<NUnit ContinueOnError="true" Assemblies="@(TestAssemblies)" OutputXmlFile="$(OutDir)nunit_results.xml" ToolPath="$(ProgramFiles)\Nunit 2.4.7\bin\">
<Output TaskParameter="ExitCode" PropertyName="NUnitResult" />
<BuildStep Condition="'$(NUnitResult)'=='0'" TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(NUnitStepId)" Status="Succeeded" />
<BuildStep Condition="'$(NUnitResult)'!='0'" TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(NUnitStepId)" Status="Failed" />

<!-- Regardless of NUnit success/failure upload the results to TFS. -->
<Exec Command="&quot;$(MSBuildProjectDirectory)\NUnitTFS.exe&quot; -n &quot;$(OutDir)nunit_results.xml&quot; -t &quot;$(TeamProject)&quot; -b &quot;$(BuildNumber)&quot; -f &quot;%(ConfigurationToBuild.FlavorToBuild)&quot; -p &quot;%(ConfigurationToBuild.PlatformToBuild)&quot; -x &quot;$(MSBuildProjectDirectory)\NUnitToMSTest.xslt&quot;" />

<!-- If NUnit failed it's time to error out -->
<Error Condition="'$(NUnitResult)'!='0'" Text="Unit Tests Failed" />

Last edited Aug 5, 2009 at 6:57 PM by MrKWatkins, version 5


prasadrmarathe Dec 16, 2009 at 7:15 AM 
how to see the n-unit test results in the test report. i mean the names of the test passed/failed.