Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #635

Merged
merged 2 commits into from May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -56,7 +56,7 @@ public class JUnit5StatelessTestsetInfoReporter extends SurefireStatelessTestset

/**
* Phrased class name of test case in the log (see xxx)
* <em>Tests run: ., Failures: ., Errors: ., Skipped: ., Time elapsed: . s, - in xxx</em>.
* <em>Tests run: ., Failures: ., Errors: ., Skipped: ., Time elapsed: . s, -- in xxx</em>.
* {@code false} by default.
* <br>
* This action takes effect only in JUnit5 provider together with a test class annotated <em>DisplayName</em>.
Expand Down

This file was deleted.

Expand Up @@ -41,7 +41,7 @@ public class TestSetStats {
private static final String ERRORS = "Errors: ";
private static final String SKIPPED = "Skipped: ";
private static final String FAILURE_MARKER = " <<< FAILURE!";
private static final String IN_MARKER = " - in ";
private static final String IN_MARKER = " -- in ";
private static final String COMMA = ", ";

private final Queue<WrappedReportEntry> reportEntries = new ConcurrentLinkedQueue<>();
Expand Down
Expand Up @@ -20,7 +20,9 @@

import javax.annotation.Nonnull;

import java.text.MessageFormat;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;

import org.apache.maven.surefire.api.report.ReportEntry;
Expand All @@ -29,14 +31,15 @@
import org.apache.maven.surefire.api.report.TestSetReportEntry;

import static java.util.Collections.unmodifiableMap;
import static org.apache.maven.plugin.surefire.report.ReporterUtils.formatElapsedTime;
import static org.apache.maven.surefire.api.util.internal.StringUtils.NL;
import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;

/**
* @author Kristian Rosenvold
*/
public class WrappedReportEntry implements TestSetReportEntry {
private static final float ONE_SECOND = 1000.0f;

private final ReportEntry original;

private final ReportEntryType reportEntryType;
Expand All @@ -49,6 +52,14 @@ public class WrappedReportEntry implements TestSetReportEntry {

private final Map<String, String> systemProperties;

/*
* Rationale: The idea is to always display four digits for visually consistent output
* Important: Keep in sync with maven-surefire-report-plugin/src/main/resources/surefire-report.properties
*/
private final MessageFormat elapsedTimeFormat = new MessageFormat(
"{0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s",
Locale.ROOT);

public WrappedReportEntry(
ReportEntry original,
ReportEntryType reportEntryType,
Expand Down Expand Up @@ -140,7 +151,7 @@ public String getStackTrace(boolean trimStackTrace) {
}

public String elapsedTimeAsString() {
return getElapsed() != null ? formatElapsedTime(getElapsed()) : null;
return getElapsed() != null ? elapsedTimeFormat.format(new Object[] {getElapsed() / ONE_SECOND}) : null;
}

String getReportSourceName() {
Expand All @@ -165,18 +176,18 @@ String getReportName() {

public String getOutput(boolean trimStackTrace) {
String outputLine =
getElapsedTimeSummary() + " <<< " + getReportEntryType().name() + "!";
getElapsedTimeSummary() + " <<< " + getReportEntryType().name() + "!";
String trimmedStackTrace = getStackTrace(trimStackTrace);
return trimmedStackTrace == null ? outputLine : outputLine + NL + trimmedStackTrace;
}

public String getElapsedTimeVerbose() {
return "Time elapsed: " + (getElapsed() != null ? elapsedTimeAsString() + " s" : "(unknown)");
return "Time elapsed: " + (getElapsed() != null ? elapsedTimeAsString() : "(unknown)");
}

public String getElapsedTimeSummary() {
String description = getName() == null ? getSourceName() : getClassMethodName();
return description + " " + getElapsedTimeVerbose();
return description + " -- " + getElapsedTimeVerbose();
}

public boolean isErrorOrFailure() {
Expand Down
Expand Up @@ -76,9 +76,9 @@ public void testDisplayNames() {
assertTrue(wr.isErrorOrFailure());
assertFalse(wr.isSkipped());
assertNull(wr.getStackTraceWriter());
assertEquals("surefire.testcase.JunitParamsTest.testSum Time elapsed: 0.012 s", wr.getElapsedTimeSummary());
assertEquals("surefire.testcase.JunitParamsTest.testSum -- Time elapsed: 0.012 s", wr.getElapsedTimeSummary());
assertEquals(
"surefire.testcase.JunitParamsTest.testSum Time elapsed: 0.012 s <<< ERROR!", wr.getOutput(false));
"surefire.testcase.JunitParamsTest.testSum -- Time elapsed: 0.012 s <<< ERROR!", wr.getOutput(false));
assertEquals("exception", wr.getMessage());
}

Expand Down Expand Up @@ -147,6 +147,6 @@ public void testElapsed() {
ReportEntry reportEntry = new SimpleReportEntry(NORMAL_RUN, 1L, className, null, null, null);
WrappedReportEntry wr = new WrappedReportEntry(reportEntry, null, 12, null, null);
String elapsedTimeSummary = wr.getElapsedTimeSummary();
assertEquals("[0] 1, 2, 3 (testSum) Time elapsed: 0.012 s", elapsedTimeSummary);
assertEquals("[0] 1, 2, 3 (testSum) -- Time elapsed: 0.012 s", elapsedTimeSummary);
}
}
Expand Up @@ -193,7 +193,7 @@ public void shouldReportTestsetLifecycle() {
.hasSize(2)
.containsSequence(
"Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.03 s "
+ "<<< FAILURE! - in pkg.MyTest",
+ "<<< FAILURE! -- in pkg.MyTest",
"pkg.MyTest failed");
verifyNoMoreInteractions(consoleLogger);
}
Expand Down
Expand Up @@ -51,6 +51,6 @@ public void test47() throws Exception {
containsString("Time elapsed: 1."),
containsString("Time elapsed: 1 s"),
containsString("Time elapsed: 0.9")));
assertThat(result, endsWith(" s - in concurrentjunit47.src.test.java.junit47.BasicTest"));
assertThat(result, endsWith(" s -- in concurrentjunit47.src.test.java.junit47.BasicTest"));
}
}
Expand Up @@ -381,7 +381,7 @@ public void testJupiterEngineWithDisplayNames() throws VerificationException {

validator
.getSurefireReportsFile("junitplatformenginejupiter.DisplayNameTest.txt", UTF_8)
.assertContainsText(" - in << ✨ >>");
.assertContainsText(" -- in << ✨ >>");

validator
.getSurefireReportsFile("junitplatformenginejupiter.DisplayNameTest-output.txt", UTF_8)
Expand Down
Expand Up @@ -32,9 +32,9 @@
* Example, UnlistedTest is the problem here because it runs with filtered out methods:
*
* Running pkg.UnlistedTest
* Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in pkg.UnlistedTest
* Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s -- in pkg.UnlistedTest
* Running pkg.RunningTest
* Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in pkg.RunningTest
* Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s -- in pkg.RunningTest
*
* Results:
*
Expand Down
Expand Up @@ -115,7 +115,9 @@ public void testMethodsParallelWithSuite() throws VerificationException {
containsString("Time elapsed: " + delayMax)));
assertThat(
line,
anyOf(endsWith(" s - in surefire747.SuiteTest1"), endsWith(" s - in surefire747.SuiteTest2")));
anyOf(
endsWith(" s -- in surefire747.SuiteTest1"),
endsWith(" s -- in surefire747.SuiteTest2")));
}
}
}
Expand Down