在TeamCity中使用MBUnit

在TeamCity中使用MBUnit

问题描述:

我正在用TeamCity持续集成服务器编译Linux上的NAnt项目。我已经能够通过在命令行运行程序上运行单声道来生成测试报告,但没有像使用NAnt Runner一样使用报告的选项。我也使用MBUnit作为测试框架。在TeamCity中使用MBUnit

如何合并测试报告并显示“Tests failed:1(1 new),passed:3049”for build?

更新:看看MBUnitTask其使用将发送的TeamCity从NUnit的预期,因此,您可以使用所有的TeamCity的功能用于测试的消息南特任务。

MBUnitTask

更新: Galio有更好的支持,所以你只需要引用,而不是MbUnit的3.5的dll Galio MbUnit的3.5 dll文件,并切换到galio亚军,使其工作。

Gallio now has an extension输出TeamCity的服务消息的文件。 只需使用包含的Gallio.NAntTasks.dll并启用TeamCity扩展。 (此won't be necessary in the next release

+1

遐我更新了这个前些天包括,galio使生活变得更轻松 – 2009-05-19 12:12:40

TeamCity监视构建的命令行输出。您可以通过将特定标记插入该输出来让它知道您的测试如何进行。请参阅http://www.jetbrains.net/confluence/display/TCD3/Build+Script+Interaction+with+TeamCity。例如

##teamcity[testSuiteStarted name='Test1'] 

会让TeamCity知道一组测试已经开始。使用MbUnit,您无法在测试运行时输出这些标记,但可以转换它输出的XML文件。下面是我使用的XSL:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text"/> 
    <xsl:template match="/"> 

     <xsl:apply-templates/> 

    </xsl:template> 

    <xsl:template match="assemblies/assembly"> 
##teamcity[testSuiteStarted name='<xsl:value-of select="@name" />'] 

     <xsl:apply-templates select="//run" /> 

##teamcity[testSuiteFinished name='<xsl:value-of select="@name" />'] 
    </xsl:template> 

    <xsl:template match="run"> 

     <xsl:choose> 
      <xsl:when test="@result='ignore' or @result='skip'"> 
     ##teamcity[testIgnored name='<xsl:value-of select="@name" />' message='Test Ignored'] 
      </xsl:when> 
      <xsl:otherwise> 
     ##teamcity[testStarted name='<xsl:value-of select="@name" />'] 
      </xsl:otherwise> 
     </xsl:choose> 


     <xsl:if test="@result='failure'"> 
      ##teamcity[testFailed name='<xsl:value-of select="@name" />' message='<xsl:value-of select="child::node()/message"/>' details='<xsl:value-of select="normalize-space(child::node()/stack-trace)"/>'] 
     </xsl:if> 


     <xsl:if test="@result!='ignore' and @result!='skip'"> 
     ##teamcity[testFinished name='<xsl:value-of select="@name" />'] 
     </xsl:if> 

    </xsl:template> 

</xsl:stylesheet> 

这就是我想出了

我怎样才能在测试报告中合并吗?

首先,您需要让mbunit生成XML和HTML报告。命令行参数看起来像这样

/rt:Xml /rt:Html /rnf:mbunit /rf:..\reports 

这将生成报告到目录名为报告和文件将被称为mbunit.xml和mbunit.html

接下来我们要添加这些文件作为文物在构建

build\reports\* => Reports 

最后一步就是要告诉TeamCity的将其添加为一个选项卡构建

找到.BuildServer \设置\主config.xm升并添加以下行 (在Windows这是在C:\ Documents和Settings \,在Linux上它是在/根目录)

<report-tab title="Tests" basePath="Reports" startPage="mbunit.html" /> 

如何显示“测试失败:1(1新),通过:3049“的构建?

TeamCity查找名为teamcity-info.xml的文件,您可以在其中显示消息。实际测试计数实际上只是纯文本。我认为你可以将文件添加为工件,但是我也将其放在了构建的根目录中。

在南特你要使用这个命令做MbUnit的XML报告

<style style="includes\teamcity-info.xsl" in="reports\mbunit.xml" out="..\teamcity-info.xml" /> 

实际XSL看起来像这样的XSLT。 (注意:{和}在XSL被保留,所以我们必须使用PARAMS)

<?xml version="1.0" encoding="ISO-8859-1"?> 

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:param name="cbl" select="'{'"/> 
<xsl:param name="cbr" select="'}'"/> 
<xsl:template match="/"> 
<xsl:for-each select="report-result/counter"> 

<build number="1.0.{concat($cbl,'build.number',$cbr)}"> 
    <xsl:if test="@failure-count &gt; 0"> 
     <statusInfo status="FAILURE">  
      <text action="append"> Tests failed: <xsl:value-of select="@failure-count"/>, passed: <xsl:value-of select="@success-count"/></text> 
     </statusInfo> 
    </xsl:if> 
    <xsl:if test="@failure-count = 0"> 
     <statusInfo status="SUCCESS"> 
      <text action="append"> Tests passed: <xsl:value-of select="@success-count"/></text> 
     </statusInfo> 
    </xsl:if> 

</build> 
</xsl:for-each> 

</xsl:template> 
</xsl:stylesheet> 

这会给你看起来像这样

<build number="1.0.{build.number}"> 
    <statusInfo status="FAILURE"> 
     <text action="append">Tests failed: 16, passed: 88</text> 
    </statusInfo> 
</build> 

TeamCity的边栏小工具为Windows Vista,Windows 7的 http://teamcity-gadget.com