在 TeamCity 构建中集成 Roxy Unit Tester

Integrating Roxy Unit Tester in a TeamCity build

Marklogic 对 roxy 的描述如下:

Roxy Unit Tester produces JUnit XML output so you can use it with your favorite continuous testing tool

有人知道如何在 TeamCity 构建中实际集成 Roxy Unit Tester 吗?

具体来说,我正在寻找一种从 TeamCity 调用单元测试执行的方法以及一种检索单元测试输出的方法。理想情况下,能够在测试未全部成功通过时使构建失败。

Roxy 的命令行界面(ml 或ml.bat)可用于运行 命令行单元测试。 XML 返回的是某种标准格式(jUnit 或其他格式),可以对其进行解析并用于确定测试的执行方式。

我们将 Roxy 测试与 Jenkins 的 ml 命令结合使用,并根据结果停止我们的构建过程。

此功能的(非常薄的)信息可以在这里找到: https://github.com/marklogic/roxy/wiki/Deployer

基本上:

> ml <environment> test

然后查看输出,看看这对您有何帮助。

TeamCity 集成“我个人最喜欢的 CI 构建系统 -- 我会使用 "Command Line" Runner”,选择 "Custom Script" 并遵循 David Ennis 的建议。

要报告测试结果和构建状态,请使用 Team City“[服务消息] 界面。2

使用"Flow ID"s 分隔组件。 对每个测试套件使用 "Test suite messages"。这可以包括捕获输出以显示在仪表板中。

对于每个测试,您都可以生成不同的结果。

我没用过,不过貌似可以,"XML Report Processing"

The XML Report processing build feature allows using report files produced by an external tool in TeamCity. TeamCity will parse the specified files on the disk and report the results as the build results.
The report parsing can also be initiated from within the build via service messages.
XML Report Processing supports the following testing frameworks:
JUnit Ant task
Maven Surefire/Failsafe plugin
NUnit-Console XML reports
TRX reports (for MSTest 2005/2008/2010/2012/2013/2015 and VSTest 2012/2013/2015)
Google Test XML reports
XML output from CTest

尽管使用 ml <environment> test 也是一个完全有效的解决方案,但我采用了稍微不同的方法:

可以直接调用 xquery 模块(即 default.xqy),它是 运行 这个地址的测试:http://your-server-name:test-app-port-number/test/

看模块的代码,在参数"func"中传值"run"会触发执行指定的"suite"和return中的结果指定的 "format".

从那里,我创建了一个简单的 Power-Shell 脚本,它首先调用 "list" 方法来检索已部署测试套件的列表

Function Get-Tests-List {
    Write-Host "Retrieving test list"
    $body = @{ 
        func="list" 
    }
    [xml]$tests = Invoke-RestMethod -Method Post -Uri $url -Headers $headers -Body $body
    [System.Xml.XmlNamespaceManager] $nsmgr = $tests.NameTable;
    $nsmgr.AddNamespace('t','http://marklogic.com/roxy/test');
    $root = $tests.DocumentElement
    $root.SelectNodes("//t:suite", $nsmgr) | Select path
}

,然后循环遍历此列表以执行测试并将结果保存为 JUnit xml 文件

$url = "http://xxxxx:8102/test/"
$headers = @{"Authorization"="Digest username=""xxxx"", realm=""public"", nonce="""", uri=""/test/"", response=""xxxxxxxxxxx"", opaque="""""}
$output_folder = "C:\DeploymentScripts\test-outputs\"

$suites = Get-Tests-List

foreach($suite in $suites) {
    $body = @{ 
        func="run" 
        format="junit" 
        runsuiteteardown = "true"
        runteardown = "true"
        suite=$suite.path
    }
    Invoke-RestMethod -Method Post -Uri $url -Headers $headers -Body $body -OutFile ("{0}{1}.xml" -f $output_folder,$suite.path)
}

然后将这些文件传递给 "XML report processing" 构建功能,该功能负责报告测试结果,甚至在需要时使构建失败。