VSTS 测试、JUnit 和 VSTS Rest API
VSTS Test, JUnit and the VSTS Rest API
注意:请记住,我从未使用过 VSTS 测试,所以我的一些评论可能是我的错误。我广泛地使用了 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>
我不知道我是如何从 JUnit XML 文件中获取所需的方式来使用 VSTS Rest API.
希望得到一些指导。
谢谢
选项 1:
从容器中复制测试结果并使用 Publish Test Results
任务,它可以解析 JUnit 格式的 XML 测试结果。 docker cp containerName:/path/to/testresults.xml ./testresults.xml
应该可以解决问题。
选项 2:编写一个简单的程序来解析测试结果并输出一个 JSON 文档,然后 运行 在您的容器中。
我会说选项 1 更好,但这只是我的意见。我用其他工具的测试结果完全做到了这一点。
注意:请记住,我从未使用过 VSTS 测试,所以我的一些评论可能是我的错误。我广泛地使用了 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>
我不知道我是如何从 JUnit XML 文件中获取所需的方式来使用 VSTS Rest API.
希望得到一些指导。
谢谢
选项 1:
从容器中复制测试结果并使用 Publish Test Results
任务,它可以解析 JUnit 格式的 XML 测试结果。 docker cp containerName:/path/to/testresults.xml ./testresults.xml
应该可以解决问题。
选项 2:编写一个简单的程序来解析测试结果并输出一个 JSON 文档,然后 运行 在您的容器中。
我会说选项 1 更好,但这只是我的意见。我用其他工具的测试结果完全做到了这一点。