Reputation: 1812
Note: please keep in mind that I have never worked with VSTS Test so some of my comments may me wrong. I have worked with the rest of VSTS extensively.
I have a task to publish some JUnit test results XML into VSTS online Test:
My tests are run within an Ubuntu Docker container so I want to use the VSTS rest API to publish them. Here is the rest API documentation:
https://learn.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
Which works fine but the POST body example is 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
}
]
} ]
Whereas, my tester and his test output is giving me 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>
I have no idea how I get from a JUnit XML file into the desired way of doing it with the VSTS Rest API.
Would love some guidance.
thanks
Upvotes: 1
Views: 888
Reputation: 59016
Option 1:
Copy the test results out of your container and use the Publish Test Results
task, which can parse JUnit formatted XML test results. docker cp containerName:/path/to/testresults.xml ./testresults.xml
should do the trick.
Option 2: Write a simple program to parse the test results and output a JSON document, then run it in your container.
I'd say Option 1 is better, but that's just my opinion. I've done exactly that with test results from other tools.
Upvotes: 2