【问题标题】:Using MBUnit in TeamCity在 TeamCity 中使用 MBUnit
【发布时间】:2010-09-05 09:53:57
【问题描述】:

我正在使用 TeamCity 持续集成服务器在 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 即可使其工作。

【问题讨论】:

    标签: mono nant teamcity mbunit


    【解决方案1】:

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

    【讨论】:

    • 是的,我前几天更新了这个内容,加里奥让生活变得更轻松
    【解决方案2】:

    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>
    

    【讨论】:

      【解决方案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 中是保留的,所以我们必须使用参数)

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-01-15
          • 1970-01-01
          • 1970-01-01
          • 2023-03-03
          • 2011-04-10
          • 1970-01-01
          • 2011-09-16
          相关资源
          最近更新 更多