Matt Mitchell
Matt Mitchell

Reputation: 41823

What is the bare minimum required to get NUnit tests to integrate with Visual Studio regular build?

I'm aware there are dozens of questions about this and blog after blog post but can someone put the simplest answer (or link to the existing question if there is an appropriate answer) to get the following working on Visual Studio 2005:

  1. NUnit tests execute on Visual Studio regular build (e.g. the absolute minimum changes to existing *.proj file to get NUnit included in MSBuild compile). If it doesn't overcomplicate things, is there a good way to use the MSBuild Community Tasks Project as a binary rather than installed on each dev machine?

  2. Test failures show in error list/warnings.

  3. Test failures halt release compilation.

Thanks for any help!

Upvotes: 0

Views: 619

Answers (3)

Dean
Dean

Reputation: 5946

To do this properly you probably want some kind of Continuous Integration Server like TeamCity or Cruise Control .

You can then add nUnit tests to your MsBuild script using the following

<!--BEGIN RUNNING UNIT TESTS-->
  <Choose>
    <When Condition=" '$(Configuration)' == 'Release' ">
      <ItemGroup>
        <TestAssemblies Include="$(BuildDir)\Builds\Release\BusinessLayer.Tests.dll" />
        <TestAssemblies Include="$(BuildDir)\Builds\Release\ResourceAccessLayer.Tests.dll" />
      </ItemGroup>
    </When>
    <Otherwise>
      <ItemGroup>
        <TestAssemblies Include="$(BuildDir)\Builds\Debug\BusinessLayer.Tests.dll" />
        <TestAssemblies Include="$(BuildDir)\Builds\Debug\ResourceAccessLayer.Tests.dll" />
      </ItemGroup>
    </Otherwise>
  </Choose>
  <UsingTask TaskName="NUnit" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)" />
  <Target Name="Test" DependsOnTargets="Build">
    <NUnit NUnitVersion="NUnit-2.4.6" Assemblies="@(TestAssemblies)" />
  </Target>
<!--RUNNING UNIT TESTS-->

You can add the condition to the target that if the configuration is Release and the task fails then then the build fails.

I think this should cover points 1 and 3

EDIT: The other way to do it would be to run the nUnit tests using the pre/post build step in Visual Studio, this and this may help.

Hope this helps

Upvotes: 1

Ray Tayek
Ray Tayek

Reputation: 10003

you may find this list useful: http://groups.google.com/group/nunit-discuss

Upvotes: 1

Jamie Ide
Jamie Ide

Reputation: 49261

You can easily accomplish this in TeamCity. You don't even need to use MSBuild; TeamCity can build from the solution file and can be configured to run NUnit tests. It performs all the functions you list in point 2 and creates trend charts and reports as well.

Upvotes: 1

Related Questions