在TeamCity中使用MBUnit

时间:2008-08-06 07:41:12

标签: mono nant teamcity mbunit

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

如何合并测试报告并显示“测试失败:1(1新),传递:3049”用于构建?

更新:看看MBUnitTask它的NAnt任务,该任务使用TeamCity期望从NUnit发送的消息,因此它允许您使用TeamCity的所有功能进行测试。

MBUnitTask

更新:Galio有更好的支持,所以你只需要引用Galio MBUnit 3.5 dll而不是MBUnit 3.5 dll并切换到galio runner以使其正常工作。

4 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:4)

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>

答案 2 :(得分:3)

这就是我提出的

如何合并测试报告?

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

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

这会将报告生成一个名为reports的目录,该文件将被称为mbunit.xml和mbunit.html

接下来我们要在构建

上添加这些文件作为工件
build\reports\* => Reports

最后一步是告诉teamcity将其添加为构建

的选项卡

找到.BuildServer \ config \ main-config.xml并添加此行 (在Windows上,这是在c:\ Documents and Settings \,在linux上它位于/ root目录中)

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

如何显示“测试失败:1(1新),传递:3049”用于构建?

TeamCity会查找名为teamcity-info.xml的文件,您可以在其中粘贴要显示的邮件。实际测试计数实际上只是纯文本。我想你可以把文件添加为工件,但我也在构建的根目录中得到它。

在NAnt中,您将要使用此命令在MBUnit XML报告上执行XSLT

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

实际的xsl看起来像这样。 (注意:{和}在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>

答案 3 :(得分:-1)

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