首页 文章

VSTS测试,JUnit和VSTS Rest API

提问于
浏览
0

Note :请记住,我从未使用过VSTS测试,所以我的一些评论可能是错的 . 我与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>

我不知道如何从JUnit XML文件中获得使用VSTS Rest API实现它的方法 .

会喜欢一些指导 .

谢谢

1 回答

  • 1

    选项1:将测试结果复制出容器并使用 Publish Test Results 任务,该任务可以解析JUnit格式的XML测试结果 . docker cp containerName:/path/to/testresults.xml ./testresults.xml 应该做的伎俩 .

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

    我会说选项1更好,但这只是我的意见 . 我已经完成了其他工具的测试结果 .

相关问题