我正在向此处定义的 guestAuth/app/rest/builds/id:2777/statistics
发出请求,http://confluence.jetbrains.com/display/TW/REST+API+Plugin#RESTAPIPlugin-OtherBuildRequests 。如果我正确理解文档,它应该列出此处定义的参数,http://confluence.jetbrains.com/display/TCD8/Custom+Chart#CustomChart-listOfDefaultStatisticValues ,但我找不到 PassedTestCount
和 FailedTestCount
。
还有其他方法可以获取这些值吗?
最佳答案
如果我理解正确,TeamCity 的工作方式是,如果运行的测试受支持,它们将显示在 Tests
下构建选项卡,然后您将能够在 REST API 中的两个位置看到它们。
首先在/guestAuth/app/rest/builds/id:X
下其中 X 是版本 ID 号。您将看到的是 <statusText>
标签将包含如下文本:
<statusText>Tests passed: 4</statusText>
<statusText>Tests failed: 2 (2 new), passed: 6</statusText>
<statusText>Tests failed: 2, passed: 6</statusText>
理论上你可以解析得到你的数字。
但是,它们也位于/guestAuth/app/rest/builds/id:X/statistics
下使用以下标签:
<property name="FailedTestCount" value="2"/>
<property name="PassedTestCount" value="6"/>
但是,如果没有失败的测试,则不会出现“FailedTestCount”属性标记。
如果您的测试没有显示在 Test
下,那么你可以查看TeamCity Service Messages for Build Script Interaction如果发现,可以报告测试开始/结束并在中间失败。
例如,您可以仅使用命令行自定义脚本构建步骤来创建新的构建:
echo "##teamcity[testSuiteStarted name='suite.name']"
echo "##teamcity[testSuiteStarted name='nested.suite']"
echo "##teamcity[testStarted name='package_or_namespace.ClassName.TestName']"
echo "##teamcity[testFailed name='package_or_namespace.ClassName.TestName' message='The number should be 20000' details='junit.framework.AssertionFailedError: expected:<20000> but was:<10000>|n|r at junit.framework.Assert.fail(Assert.java:47)|n|r at junit.framework.Assert.failNotEquals(Assert.java:280)|n|r...']"
echo "##teamcity[testFinished name='package_or_namespace.ClassName.TestName']"
echo "##teamcity[testStarted name='package_or_namespace.ClassName.TestNameTwo']"
echo "##teamcity[testFinished name='package_or_namespace.ClassName.TestNameTwo']"
echo "##teamcity[testSuiteFinished name='nested.suite']"
echo "##teamcity[testSuiteFinished name='suite.name']"
最终会显示:
<property name="FailedTestCount" value="1"/>
<property name="PassedTestCount" value="1"/>
下/guestAuth/app/rest/builds/id:X/statistics
如果你运行测试。希望有帮助。
关于teamcity - 如何在 TeamCity 中获取 PassedTestCount 和 FailedTestCount?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19542595/