Search code examples
cruisecontrol.netxunit.netccnet-config

How to integrate xUnit.net with CruiseControl.net


I have a continuous integration server that discovers and runs assemblies with NUnit tests. I would like to add some assemblies with xUnit.net tests to the mix. How would I do that?


Solution

    1. Download xunit-build-xyzw.zip from xUnit.net on CodePlex and extract it to, for example, C:\Program Files\xUnit.net. Add this location to PATH environment variable
      • be sure to have no trailing semicolon
    2. Modify your CC.NET *.build script to discover assemblies by convention, as outlined below
      • note that command line argument syntax no longer has equals sign
    3. In C:\Program Files\CruiseControl.NET\server\ccnet.config, Merge XML files produced by NUnit runner and by xUnit.net runner, as outlined below
      • merging happens after build, irrespective of build status
      • be sure results of test run get deleted in the beginning of build script
    4. Restart CC.NET
    5. Download xUnitSummary.xsl from xUnit.net on GitHub and place it in C:\Program Files (x86)\CruiseControl.NET\WebDashboard\xsl
    6. In C:\Program Files\CruiseControl.NET\WebDashboard\dashboard.config, modify buildPlugins element as outlined below
    7. Restart IIS

    Additional info: CruiseControl.Net – Server Installation at Neal's Blog


    Step 2:

    <project default="RunTests_xUnit">
       <target name="RunTests_xUnit" description="Runs the discovered xUnit.net unit tests" depends="someCompileStep">
    
          <!-- Outer loop to search through a list of different locations -->
          <!-- Folders to be searched should listed as a semicolon deliminated list in the 'in' attribute -->
          <foreach item="String" in="${TestAssemblyOutputPath}" delim=" ;" property="testsPath">
             <echo message="Searching for xUnit.net test suites in ${testsPath}" />
    
            <!-- Inner loop to search for dlls containing unit tests -->
            <foreach item="File" property="filename">
              <in>
                <items basedir="${testsPath}">
                      <!-- see http://nant.sourceforge.net/release/0.91/help/types/fileset.html for how to include or exclude specific files or file patterns -->
    
                      <!-- attempt to run tests in any dlls whose name ends with UnitTestSuite.dll' -->
                      <include name="**UnitTestSuite.dll" />
                </items>
              </in>
              <do>
                <property name="testDLLName" value="${path::get-file-name-without-extension(filename)}" />
                <echo message="Testing ${testDLLName} with xUnit.net" />
    
                   <exec program="${xunit-console.exe}" failonerror="true" resultproperty="resultVal">
                      <arg line="${testsPath}\${testDLLName}.dll /xml ${xUnitTestLogsFolder}${testDLLName}-xUnitResults.xml" />
                   </exec>
                   <fail message="Failures reported in ${testDLLName}." failonerror="true" unless="${int::parse(resultVal)==0}" />
              </do>
            </foreach>
          </foreach>
       </target>
    </project>
    

    Step 3:

    <publishers>
       <merge>
          <files>
             <file>C:\logs-location\xUnitTestLogs\*UnitTestSuite-xUnitResults.xml</file>
             <file>C:\logs-location\TestLogs\*Tests-Results.xml</file>
          </files>
       </merge>
       <xmllogger />
       <statistics />
    </publishers>
    

    Step 5:

    <buildPlugins>
        <buildReportBuildPlugin>
            <xslFileNames>
             ...
                <xslFile>xsl\xUnitSummary.xsl</xslFile>
            </xslFileNames>
        </buildReportBuildPlugin>
        ...
       <xslReportBuildPlugin description="xUnit.net Report" actionName="xUnitReport" xslFileName="xsl\xUnitSummary.xsl" />
       ...
    </buildPlugins>