VSTS测试,JUnit和VSTS Rest API

时间:2018-07-04 22:48:08

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

注意:请记住,我从未使用过VSTS Test,因此我的某些评论可能对我有误。我已经与VSTS的其余部分进行了广泛的合作。

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

我的测试在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文件转换为所需的实现方式。

希望得到一些指导。

谢谢

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题