views:

269

answers:

3

Hi,

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!

+1  A: 

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

Dean
Hi, but this won't use the regular Visual Studio build will it? I.e. developers will need to install a client for CruiseControl etc. and then build outside of Visual Studio right?
Graphain
+1  A: 

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.

Jamie Ide
+1  A: 

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

Ray Tayek