views:

239

answers:

2

To cut to the chase, can the TeamCity .NET NUnitLauncher process Microsoft csproj files?

I ask this question because of the following.

I have a NANT build script. In this script I have a number of tests which use nunit-console.exe (which ships with NUnit v2.5.2).

An example of a test in my Nant build file is:

<target name="x.Commons.Tests" depends="xCore">
<exec program="${nunit-console.exe}" commandline="${nunit-console.args} Core\x.Commons.Tests\x.Commons.Tests.csproj" failonerror="${nunit-console.failonerror}"/>
 </target>

FailOnError is set to false, and the nunit-console.args is set to '/nologo'.

When I run these tests on my local machine I get test output. However when I instruct TeamCity to build my NAnt build file, and instruct it to process the test targets I get no test output to TeamCity. I can see in the log that nunit-colsole.exe is producing test result output but Im not seeing this in the TeamCity dashboard.

After reading around I found some articles indicating that extra steps are required to get this input into TeamCity. Hence I modified my test to:

    <target name="x.Configuration.Tests" depends="xCore">
  <mkdir dir="C:\Tools\NUnit\bin\net-2.0\addins"/>
  <copy file="${teamcity.dotnet.nunitaddin}-2.5.0.dll" todir="C:\Tools\NUnit\bin\net-2.0\addins"/>
  <copy file="${teamcity.dotnet.nunitaddin}-2.5.0.pdb" todir="C:\Tools\NUnit\bin\net-2.0\addins"/>
  <exec program="${nunit-console.exe}" commandline="${nunit-console.args} Core\x.Configuration.Tests\x.Configuration.Tests.csproj" failonerror="${nunit-console.failonerror}"/>
 </target>

Note that I also made sure the tag contains an entry of 'addins'.

However, as before I can see that the tests are working as the nunit-console.exe displays its results in the log, but Im getting no output to TeamCity.

An answer to my question, or any help would be appreciated!

+1  A: 

The way we do it is by taking advantage of TeamCity's ability to automatically pick up NUnit tests in .csproj files.

  • First, you need to install the MSBuild Community Tasks.
  • Then, set up your .csproj files the following way:

    • Have this in right after <Project>

      <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

    • Create an ItemGroup:

      <ItemGroup> <TestAssembly Include="path/to/binary.dll" /> </ItemGroup>

    • Create an NUnit target:

      <Target Name="NUnit"> <NUnit Assemblies="@(TestAssembly)" /> </Target>

  • Then, in TeamCity, in the "Runner" part of project setting, choose MSBuild as the runner and in the Targets field specify both build and nunit as targets

    Targets: build nunit

TeamCity should pick up the unit tests automatically on the next build.

DrJokepu
Cheers for the reply Dr. However I'm using the NAnt build runner not MSBuild so this suggestion is not applicable not my problem.It's a frustrating problem as I was hoping that TeamCity would pick up the test output automatically.
Fresh
A: 

Use

<copy file="${teamcity.dotnet.nunitaddin}-2.5.2.dll" todir="C:\Tools\NUnit\bin\net-2.0\addins"/>
<copy file="${teamcity.dotnet.nunitaddin}-2.5.2.pdb" todir="C:\Tools\NUnit\bin\net-2.0\addins"/>

TeamCity Addin for NUnit version should match NUnit version. Please check you TeamCity version supports NUnit 2.5.2 or download newer build.

Eugene Petrenko
Hi Eugene,I have TeamCity v2.5.4 installed and I found that it does not have a nunitaddin for NUnit 2.5.2. This is unusual as NUnit v2.5.2 has been around for over a year! I'm downloading TeamCity 2.5.5 and hopefully it'll have nunitaddin 2.5.2.However, after your suggestion I changed the version of NUnit I'm using to 2.5.0, and I'm happy to say that I then got test output being displayed in TeamCity!I appreciate the help!
Fresh
Eugene Petrenko
Eugene, you're right, NUnit 2.5.2 was released in August '09. I've been getting confused with all these versions of different products! Thanks for the help and keep up the good work at JetBrains ;)
Fresh