Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,14 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
@Parameter(property = "enablePropertiesElement", defaultValue = "true")
private boolean enablePropertiesElement;

/**
* Flag for including/excluding the event start timestamp of {@code <testsuite />} and {@code <testcase />} elements in XML reports.
*
* @since 3.5.5
*/
@Parameter(property = "reportTestTimestamp", defaultValue = "false")
private boolean reportTestTimestamp;

/**
* The current build session instance.
*/
Expand Down Expand Up @@ -2107,6 +2115,7 @@ private StartupReportConfiguration getStartupReportConfiguration(boolean isForki
isForking,
isEnableOutErrElements(),
isEnablePropertiesElement(),
isReportTestTimestamp(),
xmlReporter,
outReporter,
testsetReporter,
Expand Down Expand Up @@ -3648,6 +3657,10 @@ public boolean isEnablePropertiesElement() {
return enablePropertiesElement;
}

public boolean isReportTestTimestamp() {
return reportTestTimestamp;
}

@SuppressWarnings("UnusedDeclaration")
public void setEnablePropertiesElement(boolean enablePropertiesElement) {
this.enablePropertiesElement = enablePropertiesElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
boolean.class,
boolean.class,
boolean.class,
boolean.class,
statelessTestsetReporter,
consoleOutputReporter,
statelessTestsetInfoReporter,
Expand All @@ -111,6 +112,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
reporterConfiguration.isForking(),
reporterConfiguration.isEnableOutErrElements(),
reporterConfiguration.isEnablePropertiesElement(),
reporterConfiguration.isReportTestTimestamp(),
reporterConfiguration.getXmlReporter().clone(surefireClassLoader),
reporterConfiguration.getConsoleOutputReporter().clone(surefireClassLoader),
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public final class StartupReportConfiguration {

private final boolean enablePropertiesElement;

private final boolean reportTestTimestamp;

private final SurefireStatelessReporter xmlReporter;

private final SurefireConsoleOutputReporter consoleOutputReporter;
Expand Down Expand Up @@ -120,6 +122,7 @@ public StartupReportConfiguration(
boolean isForking,
boolean enableOutErrElements,
boolean enablePropertiesElement,
boolean reportTestTimestamp,
SurefireStatelessReporter xmlReporter,
SurefireConsoleOutputReporter consoleOutputReporter,
SurefireStatelessTestsetInfoReporter testsetReporter,
Expand All @@ -142,6 +145,7 @@ public StartupReportConfiguration(
this.isForking = isForking;
this.enableOutErrElements = enableOutErrElements;
this.enablePropertiesElement = enablePropertiesElement;
this.reportTestTimestamp = reportTestTimestamp;
this.xmlReporter = xmlReporter;
this.consoleOutputReporter = consoleOutputReporter;
this.testsetReporter = testsetReporter;
Expand Down Expand Up @@ -183,6 +187,7 @@ public StartupReportConfiguration(
isForking,
true,
true,
false,
xmlReporter,
consoleOutputReporter,
testsetReporter,
Expand Down Expand Up @@ -236,6 +241,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> instantiat
xsdSchemaLocation,
enableOutErrElements,
enablePropertiesElement,
reportTestTimestamp,
testClassMethodRunHistory);

return xmlReporter.isDisable() ? null : xmlReporter.createListener(xmlReporterConfig);
Expand Down Expand Up @@ -306,6 +312,10 @@ public boolean isEnablePropertiesElement() {
return enablePropertiesElement;
}

public boolean isReportTestTimestamp() {
return reportTestTimestamp;
}

private File resolveReportsDirectory(Integer forkNumber) {
return forkNumber == null ? reportsDirectory : replaceForkThreadsInPath(reportsDirectory, forkNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public DefaultStatelessReportMojoConfiguration(
String xsdSchemaLocation,
boolean enableOutErrElements,
boolean enablePropertiesElement,
boolean reportTestTimestamp,
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory) {
super(
reportsDirectory,
Expand All @@ -53,7 +54,8 @@ public DefaultStatelessReportMojoConfiguration(
rerunFailingTestsCount,
xsdSchemaLocation,
enableOutErrElements,
enablePropertiesElement);
enablePropertiesElement,
reportTestTimestamp);
this.testClassMethodRunHistory = testClassMethodRunHistory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
false,
false,
configuration.isEnableOutErrElements(),
configuration.isEnablePropertiesElement());
configuration.isEnablePropertiesElement(),
configuration.isReportTestTimestamp());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
getUsePhrasedTestCaseClassName(),
getUsePhrasedTestCaseMethodName(),
configuration.isEnableOutErrElements(),
configuration.isEnablePropertiesElement());
configuration.isEnablePropertiesElement(),
configuration.isReportTestTimestamp());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NullStatelessXmlReporter extends StatelessXmlReporter {
static final NullStatelessXmlReporter INSTANCE = new NullStatelessXmlReporter();

private NullStatelessXmlReporter() {
super(null, null, false, 0, null, null, null, false, false, false, false, true, true);
super(null, null, false, 0, null, null, null, false, false, false, false, true, true, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -120,6 +121,8 @@ public class StatelessXmlReporter implements StatelessReportEventListener<Wrappe

private final boolean enablePropertiesElement;

private final boolean reportTestTimestamp;

@Deprecated
public StatelessXmlReporter(
File reportsDirectory,
Expand All @@ -134,7 +137,8 @@ public StatelessXmlReporter(
boolean phrasedClassName,
boolean phrasedMethodName,
boolean enableOutErrElements,
boolean enablePropertiesElement) {
boolean enablePropertiesElement,
boolean reportTestTimestamp) {
this.reportsDirectory = reportsDirectory;
this.reportNameSuffix = reportNameSuffix;
this.trimStackTrace = trimStackTrace;
Expand All @@ -148,6 +152,7 @@ public StatelessXmlReporter(
this.phrasedMethodName = phrasedMethodName;
this.enableOutErrElements = enableOutErrElements;
this.enablePropertiesElement = enablePropertiesElement;
this.reportTestTimestamp = reportTestTimestamp;
}

@Override
Expand Down Expand Up @@ -464,6 +469,10 @@ private void startTestElement(XMLWriter ppw, WrappedReportEntry report) throws I
if (report.getElapsed() != null) {
ppw.addAttribute("time", String.valueOf(report.getElapsed() / ONE_SECOND));
}

if (reportTestTimestamp && report.getStartTime() > 0L) {
ppw.addAttribute("timestamp", toIsoInstant(report.getStartTime()));
}
}

private void createTestSuiteElement(
Expand All @@ -490,6 +499,10 @@ private void createTestSuiteElement(
ppw.addAttribute("time", String.valueOf(report.getElapsed() / ONE_SECOND));
}

if (reportTestTimestamp && report.getStartTime() > 0L) {
ppw.addAttribute("timestamp", toIsoInstant(report.getStartTime()));
}

// Count actual unique test methods and their final results from classMethodStatistics (accumulated across
// reruns)
int actualTestCount = 0;
Expand Down Expand Up @@ -640,6 +653,10 @@ private static void showProperties(XMLWriter xmlWriter, Map<String, String> syst
xmlWriter.endElement();
}

private static String toIsoInstant(long epochMillis) {
return Instant.ofEpochMilli(epochMillis).toString();
}

/**
* Handle stuff that may pop up in java that is not legal in xml.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,26 @@ public void testAssumptionFailure(ReportEntry report) {

private WrappedReportEntry wrap(ReportEntry other, ReportEntryType reportEntryType) {
int estimatedElapsed = 0;
// Skipped tests don't call testStart, and thus fallback on current time
long startTimestamp = System.currentTimeMillis();
TestSetStats testSetStats = getTestSetStats(other);

if (reportEntryType != SKIPPED) {
Integer etime = other.getElapsed();
estimatedElapsed = etime == null ? getTestSetStats(other).getElapsedSinceLastStart() : etime;
estimatedElapsed = etime == null ? testSetStats.getElapsedSinceLastStart() : etime;
startTimestamp = testSetStats.getTestStartAt();
}

return new WrappedReportEntry(other, reportEntryType, estimatedElapsed, testStdOut, testStdErr);
return new WrappedReportEntry(other, reportEntryType, startTimestamp, estimatedElapsed, testStdOut, testStdErr);
}

private WrappedReportEntry wrapTestSet(TestSetReportEntry other) {
TestSetStats testSetStats = getTestSetStats(other);
return new WrappedReportEntry(
other,
null,
other.getElapsed() != null
? other.getElapsed()
: getTestSetStats(other).getElapsedSinceTestSetStart(),
testSetStats.getTestSetStartAt(),
other.getElapsed() != null ? other.getElapsed() : testSetStats.getElapsedSinceTestSetStart(),
testStdOut,
testStdErr,
other.getSystemProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ public void testSetStart() {
lastStartAt = testSetStartAt;
}

public long getTestSetStartAt() {
return testSetStartAt;
}

public void testStart() {
testStartAt = System.currentTimeMillis();
lastStartAt = testStartAt;
}

public long getTestStartAt() {
return testStartAt;
}

private void finishTest(WrappedReportEntry reportEntry) {
reportEntries.add(reportEntry);
incrementCompletedCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class WrappedReportEntry implements TestSetReportEntry {

private final ReportEntryType reportEntryType;

private final long startTime;

private final Integer elapsed;

private final Utf8RecodingDeferredFileOutputStream stdout;
Expand All @@ -63,12 +65,14 @@ public class WrappedReportEntry implements TestSetReportEntry {
public WrappedReportEntry(
ReportEntry original,
ReportEntryType reportEntryType,
long startTime,
Integer estimatedElapsed,
Utf8RecodingDeferredFileOutputStream stdout,
Utf8RecodingDeferredFileOutputStream stdErr,
Map<String, String> systemProperties) {
this.original = original;
this.reportEntryType = reportEntryType;
this.startTime = startTime;
this.elapsed = estimatedElapsed;
this.stdout = stdout;
this.stdErr = stdErr;
Expand All @@ -78,10 +82,15 @@ public WrappedReportEntry(
public WrappedReportEntry(
ReportEntry original,
ReportEntryType reportEntryType,
long startTime,
Integer estimatedElapsed,
Utf8RecodingDeferredFileOutputStream stdout,
Utf8RecodingDeferredFileOutputStream stdErr) {
this(original, reportEntryType, estimatedElapsed, stdout, stdErr, Collections.emptyMap());
this(original, reportEntryType, startTime, estimatedElapsed, stdout, stdErr, Collections.emptyMap());
}

public long getStartTime() {
return startTime;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void setup() {
false,
true,
true,
false,
xmlReporter,
consoleOutputReporter,
infoReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void processShouldExitWithoutSayingGoodBye() throws Exception {
true,
true,
true,
false,
xmlReporter,
outputReporter,
statelessTestsetInfoReporter,
Expand Down Expand Up @@ -253,6 +254,7 @@ public void processShouldWaitForAck() throws Exception {
true,
true,
true,
false,
xmlReporter,
outputReporter,
statelessTestsetInfoReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private static StartupReportConfiguration defaultValue() {
true,
true,
true,
false,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void shouldCreateConsoleListener() {
String schema = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd";
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory = new HashMap<>();
DefaultStatelessReportMojoConfiguration config = new DefaultStatelessReportMojoConfiguration(
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, testClassMethodRunHistory);
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, false, testClassMethodRunHistory);
SurefireStatelessReporter extension = new SurefireStatelessReporter();

assertThat(extension.getVersion()).isEqualTo("3.0.2");
Expand Down Expand Up @@ -141,7 +141,7 @@ public void shouldCreateJUnit5ConsoleListener() {
String schema = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd";
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory = new HashMap<>();
DefaultStatelessReportMojoConfiguration config = new DefaultStatelessReportMojoConfiguration(
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, testClassMethodRunHistory);
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, false, testClassMethodRunHistory);
JUnit5Xml30StatelessReporter extension = new JUnit5Xml30StatelessReporter();

assertThat(extension.getVersion()).isEqualTo("3.0.2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void testMergeTestHistoryResult() throws Exception {
false,
true,
true,
false,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter(),
Expand Down Expand Up @@ -330,6 +331,7 @@ public void testLogger() {
false,
true,
true,
false,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter(),
Expand Down Expand Up @@ -397,6 +399,7 @@ public void testCreateReporterWithZeroStatistics() {
false,
true,
true,
false,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter(),
Expand Down
Loading