Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top