diff --git a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index 60e1d95c6..119ef7085 100644 --- a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -61,6 +61,7 @@ import javax.annotation.Nonnull; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -98,6 +99,8 @@ public class JUnitResultArchiver extends Recorder implements SimpleBuildStep, JU private boolean skipPublishingChecks; private String checksName; + private static final String DEFAULT_CHECKS_NAME = "Tests"; + @DataBoundConstructor public JUnitResultArchiver(String testResults) { this.testResults = testResults; @@ -286,14 +289,13 @@ public static TestResultSummary parseAndSummarize(@Nonnull JUnitTask task, Pipel if (!task.isSkipPublishingChecks()) { // If we haven't been provided with a checks name, and we have pipeline test details, set the checks name - // to be a ' / '-joined string of the enclosing blocks names. If all of that ends up being empty or null, - // set a default of 'Tests' + // to be a ' / '-joined string of the enclosing blocks names, plus 'Tests' at the end. If there are no + // enclosing blocks, you'll end up with just 'Tests'. String checksName = task.getChecksName(); if (checksName == null && pipelineTestDetails != null) { - checksName = StringUtils.join(new ReverseListIterator(pipelineTestDetails.getEnclosingBlockNames()), " / "); - } - if (Util.fixEmpty(checksName) == null) { - checksName = "Tests"; + List checksComponents = new ArrayList<>(pipelineTestDetails.getEnclosingBlockNames()); + checksComponents.add(0, DEFAULT_CHECKS_NAME); + checksName = StringUtils.join(new ReverseListIterator(checksComponents), " / "); } new JUnitChecksPublisher(build, checksName, result, summary).publishChecks(listener); } diff --git a/src/test/java/io/jenkins/plugins/junit/checks/JUnitChecksPublisherTest.java b/src/test/java/io/jenkins/plugins/junit/checks/JUnitChecksPublisherTest.java index de709e8b6..443c9e805 100644 --- a/src/test/java/io/jenkins/plugins/junit/checks/JUnitChecksPublisherTest.java +++ b/src/test/java/io/jenkins/plugins/junit/checks/JUnitChecksPublisherTest.java @@ -14,7 +14,6 @@ import io.jenkins.plugins.checks.api.ChecksPublisherFactory; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; -import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -84,7 +83,7 @@ public void extractChecksDetailsPassingTestResults() throws Exception { ChecksDetails checksDetails = getDetail(); assertThat(checksDetails.getConclusion(), is(ChecksConclusion.SUCCESS)); - assertThat(checksDetails.getName().get(), is("first")); + assertThat(checksDetails.getName().get(), is("first / Tests")); ChecksOutput output = checksDetails.getOutput().get(); @@ -112,7 +111,7 @@ public void extractChecksDetailsFailingSingleTestResult() throws Exception { ChecksDetails checksDetails = getDetail(); assertThat(checksDetails.getConclusion(), is(ChecksConclusion.FAILURE)); - assertThat(checksDetails.getName().get(), is("first")); + assertThat(checksDetails.getName().get(), is("first / Tests")); ChecksOutput output = checksDetails.getOutput().get(); @@ -139,7 +138,7 @@ public void extractChecksDetailsFailingMultipleTests() throws Exception { ChecksDetails checksDetails = getDetail(); assertThat(checksDetails.getConclusion(), is(ChecksConclusion.FAILURE)); - assertThat(checksDetails.getName().get(), is("first")); + assertThat(checksDetails.getName().get(), is("first / Tests")); ChecksOutput output = checksDetails.getOutput().get(); @@ -208,6 +207,6 @@ public void extractChecksDetailsNestedStages() throws Exception { ChecksDetails checksDetails = getDetail(); - assertThat(checksDetails.getName().get(), is("first / second")); + assertThat(checksDetails.getName().get(), is("first / second / Tests")); } }