如何将xUnit.net与CruiseControl.net集成

时间:2014-09-12 21:53:53

标签: cruisecontrol.net xunit.net ccnet-config

我有一个持续集成服务器,可以使用NUnit测试发现和运行程序集。我想添加一些带有xUnit.net测试的程序集。我该怎么做?

1 个答案:

答案 0 :(得分:2)

  1. xUnit.net on CodePlex下载xunit-build-xyzw.zip并将其解压缩到例如C:\Program Files\xUnit.net。将此位置添加到PATH环境变量
    • 请确保没有尾随分号
  2. 修改您的CC.NET *.build脚本以按惯例发现程序集,如下所述
    • 请注意,命令行参数语法不再具有等号
  3. C:\Program Files\CruiseControl.NET\server\ccnet.config中,合并由NUnit runner和xUnit.net runner生成的XML文件,如下所述
    • 合并发生在构建之后,无论构建状态如何
    • 确保在构建脚本的开头
    • 删除测试运行的结果
  4. 重新启动CC.NET
  5. xUnit.net on GitHub下载xUnitSummary.xsl并将其放入C:\Program Files (x86)\CruiseControl.NET\WebDashboard\xsl
  6. C:\Program Files\CruiseControl.NET\WebDashboard\dashboard.config中,修改buildPlugins元素,如下所述
  7. 重新启动IIS
  8. 其他信息: CruiseControl.Net – Server Installation at Neal's Blog


    第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>
    

    第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>
    

    第5步:

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