forcedotcom / LightningTestingService

Apache License 2.0
122 stars 35 forks source link

Test results in "junit" format from "sfdx force:lightning:test:run" present badly because the classname is set to an empty string #55

Closed KeithClarke closed 4 years ago

KeithClarke commented 6 years ago

When Jenkins "Publish JUnit test result report" is setup for the output of "sfdx force:lightning:test:run" that is running LTS tests, the test results for passing tests are presented as a single line (with counts and times aggregated) instead of a line per test.

The XML output lines all have an empty string for their classname:

<testcase name="c:wizContainer : body component has been created" classname="" time="1.86"></testcase>

and the presentation code appears to group by that attribute.

This code appears to provide the values:

class LightningTestResults extends TestResults {
    constructor(testApi, tests, runResultSummaries, config) {
        super(testApi.testrunid, testApi.startTime, 'force.lightning', tests, runResultSummaries, config);
    }
    getTestContainerName() {
        return '';
    }
    getTestNamespace(test) {
        return test.NamespacePrefix;
    }
    getTestName(test) {
        return test.FullName;
    }
}

and this is the equivalent for Apex (for reference):

class ApexTestResults extends TestResults {
    constructor(testApi, tests, runResultSummaries, config) {
        super(testApi.testrunid, testApi.startTime, 'force.apex', tests, runResultSummaries, config);
    }
    getTestContainerName(test) {
        return test.ApexClass.Name;
    }
    getTestNamespace(test) {
        return test.ApexClass.NamespacePrefix;
    }
    getTestName(test) {
        return test.MethodName;
    }
}

with the XML built by:

            let classname = this.getTestContainerName(test);
            if (this.getTestNamespace(test)) {
                classname = this.getTestNamespace(test) + classname;
            }
            junit += `        <testcase name="${this.getTestName(test)}" classname="${classname}" time="${test.RunTime ? msToSeconds(test.RunTime) : 0}">\n`;

Changing LightningTestResults.getTestContainerName(test) to return the same thing as LightningTestResults.getTestName(test) would be a quick fix, but perhaps a better value could be returned.

(I realize this code isn't part of LTS but perhaps you can pass this on to the relevant team?)