Skip to content

Commit 6aaea8a

Browse files
committed
[SUREFIRE-1360] Ability to disable properties for successfully passed tests
This closes #755
1 parent c17b92b commit 6aaea8a

File tree

25 files changed

+333
-14
lines changed

25 files changed

+333
-14
lines changed

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,14 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
700700
@Parameter(property = "enableOutErrElements", defaultValue = "true")
701701
private boolean enableOutErrElements;
702702

703+
/**
704+
* Flag for including/excluding {@code <properties />} element for successfully passed tests in XML reports.
705+
*
706+
* @since 3.3.1
707+
*/
708+
@Parameter(property = "enablePropertiesElement", defaultValue = "true")
709+
private boolean enablePropertiesElement;
710+
703711
/**
704712
* The current build session instance.
705713
*/
@@ -1488,6 +1496,10 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
14881496
.setProperty(
14891497
ProviderParameterNames.ENABLE_OUT_ERR_ELEMENTS_PROP,
14901498
Boolean.toString(isEnableOutErrElements()));
1499+
getProperties()
1500+
.setProperty(
1501+
ProviderParameterNames.ENABLE_PROPERTIES_ELEMENT_PROP,
1502+
Boolean.toString(isEnablePropertiesElement()));
14911503

14921504
String message = "parallel='" + usedParallel + '\''
14931505
+ ", perCoreThreadCount=" + getPerCoreThreadCount()
@@ -1497,7 +1509,8 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
14971509
+ ", threadCountClasses=" + getThreadCountClasses()
14981510
+ ", threadCountMethods=" + getThreadCountMethods()
14991511
+ ", parallelOptimized=" + isParallelOptimized()
1500-
+ ", enableOutErrElements=" + isEnableOutErrElements();
1512+
+ ", enableOutErrElements=" + isEnableOutErrElements()
1513+
+ ", enablePropertiesElement=" + isEnablePropertiesElement();
15011514

15021515
logDebugOrCliShowErrors(message);
15031516
}
@@ -1992,6 +2005,7 @@ private StartupReportConfiguration getStartupReportConfiguration(String configCh
19922005
getEncoding(),
19932006
isForking,
19942007
isEnableOutErrElements(),
2008+
isEnablePropertiesElement(),
19952009
xmlReporter,
19962010
outReporter,
19972011
testsetReporter);
@@ -2533,6 +2547,7 @@ private String getConfigChecksum() {
25332547
checksum.add(useModulePath());
25342548
checksum.add(getEnableProcessChecker());
25352549
checksum.add(isEnableOutErrElements());
2550+
checksum.add(isEnablePropertiesElement());
25362551
addPluginSpecificChecksumItems(checksum);
25372552
return checksum.getSha1();
25382553
}
@@ -3498,6 +3513,15 @@ public void setEnableOutErrElements(boolean enableOutErrElements) {
34983513
this.enableOutErrElements = enableOutErrElements;
34993514
}
35003515

3516+
public boolean isEnablePropertiesElement() {
3517+
return enablePropertiesElement;
3518+
}
3519+
3520+
@SuppressWarnings("UnusedDeclaration")
3521+
public void setEnablePropertiesElement(boolean enablePropertiesElement) {
3522+
this.enablePropertiesElement = enablePropertiesElement;
3523+
}
3524+
35013525
public MavenSession getSession() {
35023526
return session;
35033527
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
8787
String.class,
8888
boolean.class,
8989
boolean.class,
90+
boolean.class,
9091
statelessTestsetReporter,
9192
consoleOutputReporter,
9293
statelessTestsetInfoReporter);
@@ -105,6 +106,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
105106
reporterConfiguration.getEncoding().name(),
106107
reporterConfiguration.isForking(),
107108
reporterConfiguration.isEnableOutErrElements(),
109+
reporterConfiguration.isEnablePropertiesElement(),
108110
reporterConfiguration.getXmlReporter().clone(surefireClassLoader),
109111
reporterConfiguration.getConsoleOutputReporter().clone(surefireClassLoader),
110112
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader)

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java

+9
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public final class StartupReportConfiguration {
8787

8888
private final boolean enableOutErrElements;
8989

90+
private final boolean enablePropertiesElement;
91+
9092
private final SurefireStatelessReporter xmlReporter;
9193

9294
private final SurefireConsoleOutputReporter consoleOutputReporter;
@@ -111,6 +113,7 @@ public StartupReportConfiguration(
111113
String encoding,
112114
boolean isForking,
113115
boolean enableOutErrElements,
116+
boolean enablePropertiesElement,
114117
SurefireStatelessReporter xmlReporter,
115118
SurefireConsoleOutputReporter consoleOutputReporter,
116119
SurefireStatelessTestsetInfoReporter testsetReporter) {
@@ -131,6 +134,7 @@ public StartupReportConfiguration(
131134
this.encoding = charset == null ? UTF_8 : Charset.forName(charset);
132135
this.isForking = isForking;
133136
this.enableOutErrElements = enableOutErrElements;
137+
this.enablePropertiesElement = enablePropertiesElement;
134138
this.xmlReporter = xmlReporter;
135139
this.consoleOutputReporter = consoleOutputReporter;
136140
this.testsetReporter = testsetReporter;
@@ -182,6 +186,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> instantiat
182186
rerunFailingTestsCount,
183187
xsdSchemaLocation,
184188
enableOutErrElements,
189+
enablePropertiesElement,
185190
testClassMethodRunHistory);
186191

187192
return xmlReporter.isDisable() ? null : xmlReporter.createListener(xmlReporterConfig);
@@ -248,6 +253,10 @@ public boolean isEnableOutErrElements() {
248253
return enableOutErrElements;
249254
}
250255

256+
public boolean isEnablePropertiesElement() {
257+
return enablePropertiesElement;
258+
}
259+
251260
private File resolveReportsDirectory(Integer forkNumber) {
252261
return forkNumber == null ? reportsDirectory : replaceForkThreadsInPath(reportsDirectory, forkNumber);
253262
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReportMojoConfiguration.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ public DefaultStatelessReportMojoConfiguration(
4444
int rerunFailingTestsCount,
4545
String xsdSchemaLocation,
4646
boolean enableOutErrElements,
47+
boolean enablePropertiesElement,
4748
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory) {
4849
super(
4950
reportsDirectory,
5051
reportNameSuffix,
5152
trimStackTrace,
5253
rerunFailingTestsCount,
5354
xsdSchemaLocation,
54-
enableOutErrElements);
55+
enableOutErrElements,
56+
enablePropertiesElement);
5557
this.testClassMethodRunHistory = testClassMethodRunHistory;
5658
}
5759

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireStatelessReporter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
6969
false,
7070
false,
7171
false,
72-
configuration.isEnableOutErrElements());
72+
configuration.isEnableOutErrElements(),
73+
configuration.isEnablePropertiesElement());
7374
}
7475

7576
@Override

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/junit5/JUnit5Xml30StatelessReporter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
108108
getUsePhrasedTestSuiteClassName(),
109109
getUsePhrasedTestCaseClassName(),
110110
getUsePhrasedTestCaseMethodName(),
111-
configuration.isEnableOutErrElements());
111+
configuration.isEnableOutErrElements(),
112+
configuration.isEnablePropertiesElement());
112113
}
113114

114115
@Override

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/NullStatelessXmlReporter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NullStatelessXmlReporter extends StatelessXmlReporter {
2929
static final NullStatelessXmlReporter INSTANCE = new NullStatelessXmlReporter();
3030

3131
private NullStatelessXmlReporter() {
32-
super(null, null, false, 0, null, null, null, false, false, false, false, true);
32+
super(null, null, false, 0, null, null, null, false, false, false, false, true, true);
3333
}
3434

3535
@Override

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public class StatelessXmlReporter implements StatelessReportEventListener<Wrappe
118118

119119
private final boolean enableOutErrElements;
120120

121+
private final boolean enablePropertiesElement;
122+
121123
public StatelessXmlReporter(
122124
File reportsDirectory,
123125
String reportNameSuffix,
@@ -130,19 +132,21 @@ public StatelessXmlReporter(
130132
boolean phrasedSuiteName,
131133
boolean phrasedClassName,
132134
boolean phrasedMethodName,
133-
boolean enableOutErrElements) {
135+
boolean enableOutErrElements,
136+
boolean enablePropertiesElement) {
134137
this.reportsDirectory = reportsDirectory;
135138
this.reportNameSuffix = reportNameSuffix;
136139
this.trimStackTrace = trimStackTrace;
137140
this.rerunFailingTestsCount = rerunFailingTestsCount;
138141
this.testClassMethodRunHistoryMap = testClassMethodRunHistoryMap;
139142
this.xsdSchemaLocation = xsdSchemaLocation;
140-
this.enableOutErrElements = enableOutErrElements;
141143
this.xsdVersion = xsdVersion;
142144
this.phrasedFileName = phrasedFileName;
143145
this.phrasedSuiteName = phrasedSuiteName;
144146
this.phrasedClassName = phrasedClassName;
145147
this.phrasedMethodName = phrasedMethodName;
148+
this.enableOutErrElements = enableOutErrElements;
149+
this.enablePropertiesElement = enablePropertiesElement;
146150
}
147151

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

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

161-
showProperties(ppw, testSetReportEntry.getSystemProperties());
165+
if (enablePropertiesElement) {
166+
showProperties(ppw, testSetReportEntry.getSystemProperties());
167+
} else {
168+
boolean hasNonSuccess = false;
169+
for (Map<String, List<WrappedReportEntry>> statistics : classMethodStatistics.values()) {
170+
for (List<WrappedReportEntry> thisMethodRuns : statistics.values()) {
171+
if (thisMethodRuns.stream()
172+
.anyMatch(entry -> entry.getReportEntryType() != ReportEntryType.SUCCESS)) {
173+
hasNonSuccess = true;
174+
break;
175+
}
176+
}
177+
if (hasNonSuccess) {
178+
break;
179+
}
180+
}
181+
182+
if (hasNonSuccess) {
183+
showProperties(ppw, testSetReportEntry.getSystemProperties());
184+
}
185+
}
162186

163187
for (Entry<String, Map<String, List<WrappedReportEntry>>> statistics : classMethodStatistics.entrySet()) {
164188
for (Entry<String, List<WrappedReportEntry>> thisMethodRuns :

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/CommonReflectorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void setup() {
8383
null,
8484
false,
8585
true,
86+
true,
8687
xmlReporter,
8788
consoleOutputReporter,
8889
infoReporter);

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkStarterTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public void processShouldExitWithoutSayingGoodBye() throws Exception {
163163
null,
164164
true,
165165
true,
166+
true,
166167
xmlReporter,
167168
outputReporter,
168169
statelessTestsetInfoReporter);
@@ -249,6 +250,7 @@ public void processShouldWaitForAck() throws Exception {
249250
null,
250251
true,
251252
true,
253+
true,
252254
xmlReporter,
253255
outputReporter,
254256
statelessTestsetInfoReporter);

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/TestSetMockReporterFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ private static StartupReportConfiguration defaultValue() {
6767
null,
6868
true,
6969
true,
70+
true,
7071
new SurefireStatelessReporter(),
7172
new SurefireConsoleOutputReporter(),
7273
new SurefireStatelessTestsetInfoReporter());

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/StatelessReporterTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void shouldCreateConsoleListener() {
6666
String schema = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd";
6767
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory = new HashMap<>();
6868
DefaultStatelessReportMojoConfiguration config = new DefaultStatelessReportMojoConfiguration(
69-
reportsDirectory, reportNameSuffix, true, 5, schema, true, testClassMethodRunHistory);
69+
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, testClassMethodRunHistory);
7070
SurefireStatelessReporter extension = new SurefireStatelessReporter();
7171

7272
assertThat(extension.getVersion()).isEqualTo("3.0.1");
@@ -141,7 +141,7 @@ public void shouldCreateJUnit5ConsoleListener() {
141141
String schema = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd";
142142
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory = new HashMap<>();
143143
DefaultStatelessReportMojoConfiguration config = new DefaultStatelessReportMojoConfiguration(
144-
reportsDirectory, reportNameSuffix, true, 5, schema, true, testClassMethodRunHistory);
144+
reportsDirectory, reportNameSuffix, true, 5, schema, true, true, testClassMethodRunHistory);
145145
JUnit5Xml30StatelessReporter extension = new JUnit5Xml30StatelessReporter();
146146

147147
assertThat(extension.getVersion()).isEqualTo("3.0.1");

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void testMergeTestHistoryResult() throws Exception {
8686
null,
8787
false,
8888
true,
89+
true,
8990
new SurefireStatelessReporter(),
9091
new SurefireConsoleOutputReporter(),
9192
new SurefireStatelessTestsetInfoReporter());
@@ -290,6 +291,7 @@ public void testLogger() {
290291
null,
291292
false,
292293
true,
294+
true,
293295
new SurefireStatelessReporter(),
294296
new SurefireConsoleOutputReporter(),
295297
new SurefireStatelessTestsetInfoReporter());
@@ -355,6 +357,7 @@ public void testCreateReporterWithZeroStatistics() {
355357
null,
356358
false,
357359
true,
360+
true,
358361
new SurefireStatelessReporter(),
359362
new SurefireConsoleOutputReporter(),
360363
new SurefireStatelessTestsetInfoReporter());

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public void testFileNameWithoutSuffix() {
110110
false,
111111
false,
112112
false,
113+
true,
113114
true);
114115
reporter.cleanTestHistoryMap();
115116

@@ -171,6 +172,7 @@ public void testAllFieldsSerialized() throws IOException {
171172
false,
172173
false,
173174
false,
175+
true,
174176
true);
175177
reporter.testSetCompleted(testSetReportEntry, stats);
176178

@@ -274,6 +276,7 @@ public void testOutputRerunFlakyFailure() throws IOException {
274276
false,
275277
false,
276278
false,
279+
true,
277280
true);
278281

279282
reporter.testSetCompleted(testSetReportEntry, stats);
@@ -373,7 +376,7 @@ public void testOutputRerunFlakyAssumption() throws IOException {
373376
rerunStats.testSucceeded(testTwoSecondError);
374377

375378
StatelessXmlReporter reporter = new StatelessXmlReporter(
376-
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false, true);
379+
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false, true, true);
377380

378381
WrappedReportEntry testSetReportEntry = new WrappedReportEntry(
379382
new SimpleReportEntry(
@@ -537,7 +540,7 @@ public void testReporterHandlesATestWithoutMessageAndWithEmptyStackTrace() {
537540
null);
538541

539542
StatelessXmlReporter reporter = new StatelessXmlReporter(
540-
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false, true);
543+
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false, true, true);
541544

542545
reporter.testSetCompleted(testReport, stats);
543546
}

surefire-api/src/main/java/org/apache/maven/surefire/api/booter/ProviderParameterNames.java

+2
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ public class ProviderParameterNames {
4747
public static final String PARALLEL_OPTIMIZE_PROP = "paralleloptimization";
4848

4949
public static final String ENABLE_OUT_ERR_ELEMENTS_PROP = "enableouterrelements";
50+
51+
public static final String ENABLE_PROPERTIES_ELEMENT_PROP = "enablepropertieselement";
5052
}

surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportMojoConfiguration.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,23 @@ public class StatelessReportMojoConfiguration {
3838

3939
private final boolean enableOutErrElements;
4040

41+
private final boolean enablePropertiesElement;
42+
4143
public StatelessReportMojoConfiguration(
4244
File reportsDirectory,
4345
String reportNameSuffix,
4446
boolean trimStackTrace,
4547
int rerunFailingTestsCount,
4648
String xsdSchemaLocation,
47-
boolean enableOutErrElements) {
49+
boolean enableOutErrElements,
50+
boolean enablePropertiesElement) {
4851
this.reportsDirectory = reportsDirectory;
4952
this.reportNameSuffix = reportNameSuffix;
5053
this.trimStackTrace = trimStackTrace;
5154
this.rerunFailingTestsCount = rerunFailingTestsCount;
5255
this.xsdSchemaLocation = xsdSchemaLocation;
5356
this.enableOutErrElements = enableOutErrElements;
57+
this.enablePropertiesElement = enablePropertiesElement;
5458
}
5559

5660
public File getReportsDirectory() {
@@ -76,4 +80,8 @@ public String getXsdSchemaLocation() {
7680
public boolean isEnableOutErrElements() {
7781
return enableOutErrElements;
7882
}
83+
84+
public boolean isEnablePropertiesElement() {
85+
return enablePropertiesElement;
86+
}
7987
}

0 commit comments

Comments
 (0)