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

[SUREFIRE-2250] Surefire Test Report Schema properties element is not consistent with the code #758

Merged
merged 2 commits into from
Jul 7, 2024
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.
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 @@ -700,6 +700,14 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
@Parameter(property = "enableOutErrElements", defaultValue = "true")
private boolean enableOutErrElements;

/**
* Flag for including/excluding {@code <properties />} element for successfully passed tests in XML reports.
*
* @since 3.3.1
*/
@Parameter(property = "enablePropertiesElement", defaultValue = "true")
private boolean enablePropertiesElement;

/**
* The current build session instance.
*/
Expand Down Expand Up @@ -1488,6 +1496,10 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
.setProperty(
ProviderParameterNames.ENABLE_OUT_ERR_ELEMENTS_PROP,
Boolean.toString(isEnableOutErrElements()));
getProperties()
.setProperty(
ProviderParameterNames.ENABLE_PROPERTIES_ELEMENT_PROP,
Boolean.toString(isEnablePropertiesElement()));

String message = "parallel='" + usedParallel + '\''
+ ", perCoreThreadCount=" + getPerCoreThreadCount()
Expand All @@ -1497,7 +1509,8 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
+ ", threadCountClasses=" + getThreadCountClasses()
+ ", threadCountMethods=" + getThreadCountMethods()
+ ", parallelOptimized=" + isParallelOptimized()
+ ", enableOutErrElements=" + isEnableOutErrElements();
+ ", enableOutErrElements=" + isEnableOutErrElements()
+ ", enablePropertiesElement=" + isEnablePropertiesElement();

logDebugOrCliShowErrors(message);
}
Expand Down Expand Up @@ -1965,7 +1978,7 @@ private Artifact getShadefireArtifact() {

private StartupReportConfiguration getStartupReportConfiguration(String configChecksum, boolean isForking) {
SurefireStatelessReporter xmlReporter = statelessTestsetReporter == null
? new SurefireStatelessReporter(/*todo call def. constr.*/ isDisableXmlReport(), "3.0.1")
? new SurefireStatelessReporter(/*todo call def. constr.*/ isDisableXmlReport(), "3.0.2")
: statelessTestsetReporter;

xmlReporter.setDisable(isDisableXmlReport()); // todo change to Boolean in the version 3.0.0-M6
Expand All @@ -1992,6 +2005,7 @@ private StartupReportConfiguration getStartupReportConfiguration(String configCh
getEncoding(),
isForking,
isEnableOutErrElements(),
isEnablePropertiesElement(),
xmlReporter,
outReporter,
testsetReporter);
Expand Down Expand Up @@ -2533,6 +2547,7 @@ private String getConfigChecksum() {
checksum.add(useModulePath());
checksum.add(getEnableProcessChecker());
checksum.add(isEnableOutErrElements());
checksum.add(isEnablePropertiesElement());
addPluginSpecificChecksumItems(checksum);
return checksum.getSha1();
}
Expand Down Expand Up @@ -3498,6 +3513,15 @@ public void setEnableOutErrElements(boolean enableOutErrElements) {
this.enableOutErrElements = enableOutErrElements;
}

public boolean isEnablePropertiesElement() {
return enablePropertiesElement;
}

@SuppressWarnings("UnusedDeclaration")
public void setEnablePropertiesElement(boolean enablePropertiesElement) {
this.enablePropertiesElement = enablePropertiesElement;
}

public MavenSession getSession() {
return session;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
String.class,
boolean.class,
boolean.class,
boolean.class,
statelessTestsetReporter,
consoleOutputReporter,
statelessTestsetInfoReporter);
Expand All @@ -105,6 +106,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
reporterConfiguration.getEncoding().name(),
reporterConfiguration.isForking(),
reporterConfiguration.isEnableOutErrElements(),
reporterConfiguration.isEnablePropertiesElement(),
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 @@ -87,6 +87,8 @@ public final class StartupReportConfiguration {

private final boolean enableOutErrElements;

private final boolean enablePropertiesElement;

private final SurefireStatelessReporter xmlReporter;

private final SurefireConsoleOutputReporter consoleOutputReporter;
Expand All @@ -111,6 +113,7 @@ public StartupReportConfiguration(
String encoding,
boolean isForking,
boolean enableOutErrElements,
boolean enablePropertiesElement,
SurefireStatelessReporter xmlReporter,
SurefireConsoleOutputReporter consoleOutputReporter,
SurefireStatelessTestsetInfoReporter testsetReporter) {
Expand All @@ -131,6 +134,7 @@ public StartupReportConfiguration(
this.encoding = charset == null ? UTF_8 : Charset.forName(charset);
this.isForking = isForking;
this.enableOutErrElements = enableOutErrElements;
this.enablePropertiesElement = enablePropertiesElement;
this.xmlReporter = xmlReporter;
this.consoleOutputReporter = consoleOutputReporter;
this.testsetReporter = testsetReporter;
Expand Down Expand Up @@ -182,6 +186,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> instantiat
rerunFailingTestsCount,
xsdSchemaLocation,
enableOutErrElements,
enablePropertiesElement,
testClassMethodRunHistory);

return xmlReporter.isDisable() ? null : xmlReporter.createListener(xmlReporterConfig);
Expand Down Expand Up @@ -248,6 +253,10 @@ public boolean isEnableOutErrElements() {
return enableOutErrElements;
}

public boolean isEnablePropertiesElement() {
return enablePropertiesElement;
}

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 @@ -44,14 +44,16 @@ public DefaultStatelessReportMojoConfiguration(
int rerunFailingTestsCount,
String xsdSchemaLocation,
boolean enableOutErrElements,
boolean enablePropertiesElement,
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory) {
super(
reportsDirectory,
reportNameSuffix,
trimStackTrace,
rerunFailingTestsCount,
xsdSchemaLocation,
enableOutErrElements);
enableOutErrElements,
enablePropertiesElement);
this.testClassMethodRunHistory = testClassMethodRunHistory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class SurefireStatelessReporter
* Activated in the injection point of MOJO.
*/
public SurefireStatelessReporter() {
this(false, "3.0.1");
this(false, "3.0.2");
}

/**
Expand Down Expand Up @@ -69,7 +69,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
false,
false,
false,
configuration.isEnableOutErrElements());
configuration.isEnableOutErrElements(),
configuration.isEnablePropertiesElement());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.maven.surefire.extensions.StatelessReportEventListener;

/**
* The extension of {@link StatelessReportEventListener xml reporter} based on XSD version 3.0.1 for JUnit5.
* The extension of {@link StatelessReportEventListener XML reporter} based on XSD version 3.0.2 for JUnit5.
* Selectively enables phrased classes, methods and report files upon JUnit5 annotation <em>DisplayName</em>.
*
* author <a href="mailto:[email protected]">Tibor Digana (tibor17)</a>
Expand Down Expand Up @@ -108,7 +108,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
getUsePhrasedTestSuiteClassName(),
getUsePhrasedTestCaseClassName(),
getUsePhrasedTestCaseMethodName(),
configuration.isEnableOutErrElements());
configuration.isEnableOutErrElements(),
configuration.isEnablePropertiesElement());
}

@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);
super(null, null, false, 0, null, null, null, false, false, false, false, true, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public class StatelessXmlReporter implements StatelessReportEventListener<Wrappe

private final boolean enableOutErrElements;

private final boolean enablePropertiesElement;

public StatelessXmlReporter(
File reportsDirectory,
String reportNameSuffix,
Expand All @@ -130,19 +132,21 @@ public StatelessXmlReporter(
boolean phrasedSuiteName,
boolean phrasedClassName,
boolean phrasedMethodName,
boolean enableOutErrElements) {
boolean enableOutErrElements,
boolean enablePropertiesElement) {
this.reportsDirectory = reportsDirectory;
this.reportNameSuffix = reportNameSuffix;
this.trimStackTrace = trimStackTrace;
this.rerunFailingTestsCount = rerunFailingTestsCount;
this.testClassMethodRunHistoryMap = testClassMethodRunHistoryMap;
this.xsdSchemaLocation = xsdSchemaLocation;
this.enableOutErrElements = enableOutErrElements;
this.xsdVersion = xsdVersion;
this.phrasedFileName = phrasedFileName;
this.phrasedSuiteName = phrasedSuiteName;
this.phrasedClassName = phrasedClassName;
this.phrasedMethodName = phrasedMethodName;
this.enableOutErrElements = enableOutErrElements;
this.enablePropertiesElement = enablePropertiesElement;
}

@Override
Expand All @@ -158,7 +162,27 @@ public void testSetCompleted(WrappedReportEntry testSetReportEntry, TestSetStats

createTestSuiteElement(ppw, testSetReportEntry, testSetStats); // TestSuite

showProperties(ppw, testSetReportEntry.getSystemProperties());
if (enablePropertiesElement) {
showProperties(ppw, testSetReportEntry.getSystemProperties());
} else {
boolean hasNonSuccess = false;
for (Map<String, List<WrappedReportEntry>> statistics : classMethodStatistics.values()) {
for (List<WrappedReportEntry> thisMethodRuns : statistics.values()) {
if (thisMethodRuns.stream()
.anyMatch(entry -> entry.getReportEntryType() != ReportEntryType.SUCCESS)) {
hasNonSuccess = true;
break;
}
}
if (hasNonSuccess) {
break;
}
}

if (hasNonSuccess) {
showProperties(ppw, testSetReportEntry.getSystemProperties());
}
}

for (Entry<String, Map<String, List<WrappedReportEntry>>> statistics : classMethodStatistics.entrySet()) {
for (Entry<String, List<WrappedReportEntry>> thisMethodRuns :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void setup() {
null,
false,
true,
true,
xmlReporter,
consoleOutputReporter,
infoReporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public void processShouldExitWithoutSayingGoodBye() throws Exception {
null,
true,
true,
true,
xmlReporter,
outputReporter,
statelessTestsetInfoReporter);
Expand Down Expand Up @@ -249,6 +250,7 @@ public void processShouldWaitForAck() throws Exception {
null,
true,
true,
true,
xmlReporter,
outputReporter,
statelessTestsetInfoReporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private static StartupReportConfiguration defaultValue() {
null,
true,
true,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void shouldCloneXmlReporter() {
@Test
public void shouldAssertToStringXmlReporter() {
SurefireStatelessReporter extension = new SurefireStatelessReporter();
assertThat(extension.toString()).isEqualTo("SurefireStatelessReporter{version=3.0.1, disable=false}");
assertThat(extension.toString()).isEqualTo("SurefireStatelessReporter{version=3.0.2, disable=false}");
}

@Test
Expand All @@ -66,10 +66,10 @@ 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, testClassMethodRunHistory);
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, testClassMethodRunHistory);
SurefireStatelessReporter extension = new SurefireStatelessReporter();

assertThat(extension.getVersion()).isEqualTo("3.0.1");
assertThat(extension.getVersion()).isEqualTo("3.0.2");
extension.setVersion("V3");
assertThat(extension.getVersion()).isEqualTo("V3");

Expand Down Expand Up @@ -128,7 +128,7 @@ public void shouldCloneJUnit5XmlReporter() {
public void shouldAssertToStringJUnit5ConsoleReporter() {
JUnit5Xml30StatelessReporter extension = new JUnit5Xml30StatelessReporter();
assertThat(extension.toString())
.isEqualTo("JUnit5Xml30StatelessReporter{version=3.0.1, disable=false, "
.isEqualTo("JUnit5Xml30StatelessReporter{version=3.0.2, disable=false, "
+ "usePhrasedFileName=false, usePhrasedTestSuiteClassName=false, "
+ "usePhrasedTestCaseClassName=false, usePhrasedTestCaseMethodName=false}");
}
Expand All @@ -141,10 +141,10 @@ 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, testClassMethodRunHistory);
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, testClassMethodRunHistory);
JUnit5Xml30StatelessReporter extension = new JUnit5Xml30StatelessReporter();

assertThat(extension.getVersion()).isEqualTo("3.0.1");
assertThat(extension.getVersion()).isEqualTo("3.0.2");
extension.setVersion("V3");
assertThat(extension.getVersion()).isEqualTo("V3");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void testMergeTestHistoryResult() throws Exception {
null,
false,
true,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down Expand Up @@ -290,6 +291,7 @@ public void testLogger() {
null,
false,
true,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down Expand Up @@ -355,6 +357,7 @@ public void testCreateReporterWithZeroStatistics() {
null,
false,
true,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down
Loading