关于mono:在TeamCity中使用MBUnit

关于mono:在TeamCity中使用MBUnit

Using MBUnit in TeamCity

我正在使用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运行器即可使其工作。


Gallio现在具有扩展功能,可以输出TeamCity服务消息。
只需使用随附的Gallio.NAntTasks.dll并启用TeamCity扩展即可。 (在下一发行版中将不再必需)


TeamCity监视构建中的命令行输出。您可以通过在输出中插入某些标记来告知测试如何进行。请参阅http://www.jetbrains.net/confluence/display/TCD3/Build与TeamCity的交互。例如

1
##teamcity[testSuiteStarted name='Test1']

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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报告。命令行参数如下所示:

1
2
/rt:Xml /rt:Html /rnf:mbunit /rf:..\
eports

这将把报告生成到称为reports的目录中,文件将称为mbunit.xml和mbunit.html

接下来,我们想将这些文件作为工件添加到构建中

1
2
build\
eports\\* => Reports

最后一步是告诉teamcity将其添加为构建的选项卡

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

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

如何为构建显示"测试失败:1(新1次,已通过:3049)"?

TeamCity寻找一个名为teamcity-info.xml的文件,您可以在其中粘贴要显示的消息。实际测试计数实际上只是纯文本。我认为您可以将文件作为工件添加,但我也将其保存在构建的根目录中。

在NAnt中,您将要使用此命令对MBUnit XML报告进行XSLT。

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

实际的xsl看起来像这样。
(注意:{和}在xsl中保留,因此我们必须使用params)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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 > 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>

这将为您提供一个看起来像这样的文件

1
2
3
4
5
<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


推荐阅读