【问题标题】:VSTS Test, JUnit and the VSTS Rest APIVSTS 测试、JUnit 和 VSTS Rest API
【发布时间】:2018-07-05 08:05:12
【问题描述】:

注意:请记住,我从未使用过 VSTS 测试,所以我的一些 cmets 可能是我的错误。我与 VSTS 的其余部分进行了广泛的合作。

我的任务是将一些 JUnit 测试结果 XML 发布到 VSTS 在线测试中:

我的测试在 Ubuntu Docker 容器中运行,因此我想使用 VSTS REST API 来发布它们。这是其余的 API 文档:

https://docs.microsoft.com/en-us/rest/api/vsts/test/?view=vsts-rest-5.0

POST https://{accountName}.visualstudio.com/{project}/_apis/test/Runs/{runId}/results?api-version=5.0-preview.5

效果很好,但 POST 正文示例是 json:

[
 {
  "testCaseTitle": "VerifyWebsiteTheme",
  "automatedTestName": 
  "FabrikamFiber.WebSite.TestClass.VerifyWebsiteTheme",
  "priority": 1,
  "outcome": "Passed"
 },
 {
  "testCaseTitle": "VerifyWebsiteLinks",
  "automatedTestName": 
  "FabrikamFiber.WebSite.TestClass.VerifyWebsiteLinks",
  "priority": 2,
  "outcome": "Failed",
  "associatedBugs": [
  {
    "id": 30
  }
]

} ]

然而,我的测试员和他的测试输出给了我 XML:

<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="10" failures="0" name="pytest" skips="12" tests="53" time="16.073">    
  <testcase classname="tests.test_api" file="tests/test_api.py" line="5" name="test_GETNotFound" time="0.4054398536682129"></testcase>    
  <testcase classname="tests.test_api" file="tests/test_api.py" line="10" name="test_POSTBadRequest[]" time="0.41185760498046875"></testcase>
  <testcase classname="tests.test_api" file="tests/test_api.py" line="10" name="test_POSTBadRequest[req1]" time="0.48476719856262207"></testcase>
  <testcase classname="tests.test_api" file="tests/test_api.py" line="10" name="test_POSTBadRequest[{}]" time="0.44095635414123535"></testcase>
  <testcase classname="tests.test_api" file="tests/test_api.py" line="10" name="test_POSTBadRequest[TEST]" time="0.4718012809753418"></testcase>
  <testcase classname="tests.test_azureFileService" file="tests/test_azureFileService.py" line="0" name="test_readFilesDirs" time="0.22459125518798828"></testcase>
</testsuite>

我不知道如何使用 VSTS Rest API 从 JUnit XML 文件中获取所需的方式。

希望得到一些指导。

谢谢

【问题讨论】:

    标签: xml junit azure-devops azure-devops-rest-api


    【解决方案1】:

    选项 1: 从容器中复制测试结果并使用Publish Test Results 任务,它可以解析 JUnit 格式的 XML 测试结果。 docker cp containerName:/path/to/testresults.xml ./testresults.xml 应该可以解决问题。

    选项 2:编写一个简单的程序来解析测试结果并输出一个 JSON 文档,然后在您的容器中运行它。

    我会说选项 1 更好,但这只是我的意见。我已经通过其他工具的测试结果做到了这一点。

    【讨论】:

    • 感谢您的提示。实际上,我什至在阅读您的评论之前就选择了选项 11。我缺乏对 Linux 的信心,这使我无法尝试使用 Publish Test Results 任务,因为我无法获得正确的路径语法。我现在已经开始工作了,而且效果很好。谢谢
    猜你喜欢
    • 2018-06-18
    • 1970-01-01
    • 2018-08-23
    • 2018-10-28
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多