CruiseControl + MsBuild + NUnit + multiple assemblies - Thea Burger's Blog

Thea Burger's Blog

Wouldn't you like to know...

News

Photo's!!!

About me

I'm Reading: General Blogs

I'm Reading: Technical Blogs

CruiseControl + MsBuild + NUnit + multiple assemblies

Eventually!!! (Uncensored: Uitf*kkeneindelik)

We've been using CruiseControl.Net now for a while, but I ran into quite a few problems along the way, one of them to get everything working with 2 different test assemblies. 

Now I can't even remember everything exactly, which is a pity, because as I ran into problems I told myself, remember this, you're going to want to blog about it... but I can give you the following. 

I use a msbuild file for all the tasks that I want to execute, most importantly to execute all our tests and display the results on the CruiseControl web dashboard. At first I tried to integrate NUnit using cc.net's tasks:

<tasks>       
    <nunit>
        <path>
D:\Projects\Komodo\tools\NUnit\bin\nunit-console.exe</path>
        <assemblies> 
            <assembly>
D:\Projects\Komodo\src\Domain\Tests\bin\Debug\
                Komodo.Domain.Tests.dll
</assembly>
            <assembly>
D:\Projects\Komodo\src\Messaging\Tests\bin\Debug\
                Komodo.Messaging.Tests.dll
</assembly>
        <
/assemblies>
    <
/nunit>
<
/tasks> 

 
But for some reason that didn't wan't to work so lekker. , so I decided to rather try and do this from msbuild. Found a very useful example on Geek Noise:
 

<Project DefaultTargets="BuildAll" 
        
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>    
        <NUnitExe>
            
&quot;D:\Projects\Komodo\tools\NUnit\bin\nunit-console.exe&quot;
        
</NUnitExe>
        <NUnitArgs>
/nologo</NUnitArgs>            
    <
/PropertyGroup>  
   
    <ItemGroup>
        <TestAssembly 
Include="Komodo.Messaging.Tests.dll">        
            <WorkingDirectory>
                
D:\Projects\Komodo\src\Messaging\Tests\bin\Debug
            
</WorkingDirectory>
        <
/TestAssembly>    
        <TestAssembly 
Include="Komodo.Domain.Tests.dll">        
            <WorkingDirectory>
                
D:\Projects\Komodo\src\Domain\Tests\bin\Debug
            
</WorkingDirectory>
        <
/TestAssembly>                        
    <
/ItemGroup>       
   
     <
Target Name="BuildAll" DependsOnTargets="Clean;Compile;UnitTest;" /
     <
Target Name="Clean">
          <MSBuild 
Projects="../src/Komodo.sln" 
              
Properties="Configuration=$(Configuration)" Targets="Clean" />
      <
/Target>

      <
Target Name="Compile">
          <MSBuild 
Projects="../src/Komodo.sln" 
              
Properties="Configuration=$(Configuration)" />
      <
/Target>

      <
Target Name="UnitTest" DependsOnTargets="Compile">
          <Exec 
ContinueOnError='true' 
                  
Command='$(NUnitEXE) $(NUnitArgs) @(TestAssembly)'
                  
WorkingDirectory='%(WorkingDirectory)' />
      <
/Target>    
<
/Project>

This worked fine when I executed the build file using the command line, last thing was to ensure that the results display on the webdashboard. Now when you execute nunit from ccnet.config, the results is automatically displayed.

To display these results, you have to create a file merge task in ccnet.config. At first, in the above example I specified where to generate the nunit xml results by using <NUnitArgs>/xml D:\Projects\Komodo\build\nunit-results.xml</NUnitArgs> , but when doing this the file is obviously overwritten every time an assembly is processed. 

To solve this I just removed that line, and pointed the file merge task to the default xml results of each execution, which is the assembly's working directory:  

<merge>
    <files>        
        <file>
            
D:\Projects\Komodo\src\Domain\Tests\bin\Debug\TestResult.xml
        
</file>
        <file>
            
D:\Projects\Komodo\src\Messaging\Tests\bin\Debug\TestResult.xml
        
</file>
    <
/files>
<
/merge>      

And, TADA, eventually I have beautiful test results of multiple assemblies!  Big Smile

PS: A post that helped me a lot in setting this up initially is here on Michael Swanson's Blog.

Comments

Michael said:

Hey Thea, thanks for your help. I used an implementation of the multiple-dll testing pattern in my article, and referenced this page as well: http://www.codeproject.com/useritems/ContinuousIntegration.asp
# October 6, 2006 7:55 AM

Thea Burger said:

Huge pleasure Michael, cool article by the way.

# October 9, 2006 7:42 PM

Another cc.net day « maonet technotes said:

Pingback from  Another cc.net day &laquo; maonet technotes

# November 21, 2008 3:43 PM