Xray-App / xray-testng-extensions

Enhanced TestNG integration with Xray Test Management for Jira
MIT License
9 stars 5 forks source link

avoid adding null comment in json reporter #16

Closed Atari361 closed 5 months ago

Atari361 commented 6 months ago

org.testng.ITestResult#getThrowable sometimes can have detailMessage=null, and this results in json-report.json having "comment":null and later a rejection from API when importing results via '/api/v2/import/execution' (Xray Cloud).

TestNG test example that generates detailMessage=null:

@Test
@XrayTest(key = "EZ-76901")
public void testFailed() {
    assert false;
}

This PR adds an extra detailMessage != null check to favoid adding null comment.

bitcoder commented 5 months ago

@Atari361 thanks for the PR. As I cannot write on your original repo, my recommendation would be to change the PR code to something like this on lines 340-355 of XrayJsonReporter.java

        if (results.size() == 1) {

            // regular test; non data-driven
            ITestResult result =  results.get(0);           
            String start = dateFormatter.format(result.getStartMillis());
            String finish = dateFormatter.format(result.getEndMillis());
            test.put("start", start);
            test.put("finish", finish);
            test.put("status", getTestStatus(result.getStatus()));
            Throwable throwable = result.getThrowable();
            if (result.getStatus() == ITestResult.FAILURE && throwable != null && throwable.getMessage() != null)
                test.put("comment", throwable.getMessage());

            // process attachments
            processAttachments(result, test);
        } 
bitcoder commented 5 months ago

I'm not sure why the build still fails here on GH on the PR, even though I've checked out the code locally and it runs. any ideas?

sonarcloud[bot] commented 5 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud