Skip to content

Commit f942700

Browse files
authored
Fixes #59 - Include hide-succes-tests option (#60)
* Fixes #59 - Include hide-succes-tests option * PR review: fix typos
1 parent dbab2d4 commit f942700

File tree

5 files changed

+98
-8
lines changed

5 files changed

+98
-8
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ The output can be printed using two Themes: UNICODE and ASCII (by default).
6060
![Imgur](https://i.imgur.com/FzcIWwe.png "ASCII Output")
6161

6262

63+
## Reduce verbosity
64+
65+
Output in large projects could become too verbose, making failures or errors difficult to find inside the printed trees.
66+
To reduce verbosity, you can a _hide successful results_ option can be configured as follows:
67+
68+
```xml
69+
<statelessTestsetInfoReporter
70+
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
71+
<hideResultsOnSuccess>true</hideResultsOnSuccess>
72+
</statelessTestsetInfoReporter>
73+
```
74+
6375
## Failure details
6476

6577
By default, `<consoleOutputReporter><disable>true</disable></consoleOutputReporter>` disables all console output. To debug test failures, it may be useful to see the console output and stack traces when a test fails. To do so, you can configure this extension like this:

src/main/java/org/apache/maven/plugin/surefire/extensions/junit5/JUnit5StatelessTestsetInfoTreeReporter.java

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class JUnit5StatelessTestsetInfoTreeReporter extends JUnit5StatelessTests
2525
private boolean printStdoutOnError;
2626
private boolean printStdoutOnFailure;
2727
private boolean printStdoutOnSuccess;
28+
private boolean hideResultsOnSuccess;
2829
private Theme theme = Theme.ASCII;
2930

3031
@Override
@@ -48,6 +49,7 @@ public Object clone(ClassLoader target) {
4849
cls.getMethod("setPrintStdoutOnError", boolean.class).invoke(clone, isPrintStdoutOnError());
4950
cls.getMethod("setPrintStdoutOnFailure", boolean.class).invoke(clone, isPrintStdoutOnFailure());
5051
cls.getMethod("setPrintStdoutOnSuccess", boolean.class).invoke(clone, isPrintStdoutOnSuccess());
52+
cls.getMethod("setHideResultsOnSuccess", boolean.class).invoke(clone, isPrintStdoutOnSuccess());
5153
cls.getMethod("setTheme", themeClass).invoke(clone, clonedTheme);
5254

5355
return clone;
@@ -98,6 +100,10 @@ public boolean isPrintStdoutOnSuccess() {
98100
return printStdoutOnSuccess;
99101
}
100102

103+
public boolean isHideResultsOnSuccess() {
104+
return hideResultsOnSuccess;
105+
}
106+
101107
public void setPrintStacktraceOnError(boolean printStacktraceOnError) {
102108
this.printStacktraceOnError = printStacktraceOnError;
103109
}
@@ -130,6 +136,10 @@ public void setPrintStdoutOnSuccess(boolean printStdoutOnSuccess) {
130136
this.printStdoutOnSuccess = printStdoutOnSuccess;
131137
}
132138

139+
public void setHideResultsOnSuccess(boolean hideResultsOnSuccess) {
140+
this.hideResultsOnSuccess = hideResultsOnSuccess;
141+
}
142+
133143
public void setTheme(Theme theme) {
134144
this.theme = theme;
135145
}
@@ -154,6 +164,7 @@ private ReporterOptions newReporterOptions() {
154164
.printStdoutOnError(isPrintStdoutOnError())
155165
.printStdoutOnFailure(isPrintStdoutOnFailure())
156166
.printStdoutOnSuccess(isPrintStdoutOnSuccess())
167+
.hideResultsOnSuccess(isHideResultsOnSuccess())
157168
.usePhrasedClassNameInRunning(isUsePhrasedClassNameInRunning())
158169
.usePhrasedClassNameInTestCaseSummary(isUsePhrasedClassNameInTestCaseSummary())
159170
.theme(getTheme())

src/main/java/org/apache/maven/plugin/surefire/report/ReporterOptions.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class ReporterOptions {
99
private final boolean printStdoutOnError;
1010
private final boolean printStdoutOnFailure;
1111
private final boolean printStdoutOnSuccess;
12+
private final boolean hideResultsOnSuccess;
1213
private final Theme theme;
1314
private final boolean usePhrasedClassNameInRunning;
1415
private final boolean usePhrasedClassNameInTestCaseSummary;
@@ -22,11 +23,16 @@ private ReporterOptions(Builder builder) {
2223
this.printStdoutOnError = builder.printStdoutOnError;
2324
this.printStdoutOnFailure = builder.printStdoutOnFailure;
2425
this.printStdoutOnSuccess = builder.printStdoutOnSuccess;
26+
this.hideResultsOnSuccess = builder.hideResultsOnSuccess;
2527
this.usePhrasedClassNameInRunning = builder.usePhrasedClassNameInRunning;
2628
this.usePhrasedClassNameInTestCaseSummary = builder.usePhrasedClassNameInTestCaseSummary;
2729
this.theme = builder.theme != null ? builder.theme : Theme.ASCII;
2830
}
2931

32+
public static Builder builder() {
33+
return new Builder();
34+
}
35+
3036
public Theme getTheme() {
3137
return theme;
3238
}
@@ -63,6 +69,10 @@ public boolean isPrintStdoutOnSuccess() {
6369
return printStdoutOnSuccess;
6470
}
6571

72+
public boolean isHideResultsOnSuccess() {
73+
return hideResultsOnSuccess;
74+
}
75+
6676
public boolean isUsePhrasedClassNameInRunning() {
6777
return usePhrasedClassNameInRunning;
6878
}
@@ -71,10 +81,6 @@ public boolean isUsePhrasedClassNameInTestCaseSummary() {
7181
return usePhrasedClassNameInTestCaseSummary;
7282
}
7383

74-
public static Builder builder() {
75-
return new Builder();
76-
}
77-
7884
public static final class Builder {
7985
private boolean printStacktraceOnError;
8086
private boolean printStacktraceOnFailure;
@@ -84,6 +90,7 @@ public static final class Builder {
8490
private boolean printStdoutOnError;
8591
private boolean printStdoutOnFailure;
8692
private boolean printStdoutOnSuccess;
93+
private boolean hideResultsOnSuccess;
8794
private Theme theme;
8895
private boolean usePhrasedClassNameInRunning;
8996
private boolean usePhrasedClassNameInTestCaseSummary;
@@ -135,6 +142,11 @@ public Builder printStdoutOnSuccess(boolean printStdoutOnSuccess) {
135142
return this;
136143
}
137144

145+
public Builder hideResultsOnSuccess(boolean hideResultsOnSuccess) {
146+
this.hideResultsOnSuccess = hideResultsOnSuccess;
147+
return this;
148+
}
149+
138150
public Builder theme(Theme theme) {
139151
this.theme = theme;
140152
return this;

src/main/java/org/apache/maven/plugin/surefire/report/TreePrinter.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
*/
4343
public class TreePrinter {
4444

45+
private static final int $ = 36;
4546
private final ConsoleLogger consoleLogger;
4647
private final List<WrappedReportEntry> classResults;
4748
private final List<WrappedReportEntry> testSetStats;
4849
private final List<String> sourceNames;
4950
private final Set<String> distinctSourceName;
5051
private final ReporterOptions options;
51-
private static final int $ = 36;
5252

5353
public TreePrinter(ConsoleLogger consoleLogger, List<WrappedReportEntry> classResults, List<WrappedReportEntry> testSetStats, ReporterOptions options) {
5454
this.consoleLogger = consoleLogger;
@@ -78,11 +78,15 @@ public void printTests() {
7878
.stream()
7979
.map(TestPrinter::new)
8080
.forEach(printer -> {
81-
printer.printTest();
81+
printer.printTest(isSuccessPrintAllowed());
8282
printer.printDetails();
8383
});
8484
}
8585

86+
private boolean isSuccessPrintAllowed() {
87+
return !options.isHideResultsOnSuccess();
88+
}
89+
8690
private class TestPrinter {
8791

8892
private final WrappedReportEntry testResult;
@@ -123,13 +127,13 @@ private void printDetails() {
123127
}
124128
}
125129

126-
private void printTest() {
130+
private void printTest(boolean isPrintSuccessAllowed) {
127131
printClass();
128132
if (testResult.isErrorOrFailure()) {
129133
printFailure();
130134
} else if (testResult.isSkipped()) {
131135
printSkipped();
132-
} else if (testResult.isSucceeded()) {
136+
} else if (isPrintSuccessAllowed && testResult.isSucceeded()) {
133137
printSuccess();
134138
}
135139
}

src/test/java/org/apache/maven/plugin/surefire/report/ConsoleTreeReporterTest.java

+51
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.codehaus.plexus.PlexusContainerException;
88
import org.codehaus.plexus.logging.Logger;
99
import org.junit.jupiter.api.BeforeAll;
10+
import org.junit.jupiter.api.DisplayName;
1011
import org.junit.jupiter.api.Test;
1112
import org.junit.jupiter.api.extension.ExtendWith;
1213
import org.mockito.junit.jupiter.MockitoExtension;
@@ -90,4 +91,54 @@ void testSetCompleted() {
9091
//TODO see how to unit test this
9192
}
9293

94+
@Test
95+
void testHideSuccess() {
96+
//TestStarting parameters
97+
SimpleReportEntry simpleReportEntry1 = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest", "Nested Sample", null, null);
98+
SimpleReportEntry simpleReportEntry2 = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest", "Inner Test", null, null);
99+
SimpleReportEntry simpleReportEntry3 = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest$InnerInnerTest", "Inner Inner Test", null, null);
100+
SimpleReportEntry simpleReportEntry4 = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest$InnerInnerTest$InnerInnerInnerTest", "Inner Inner Inner Test", null, null);
101+
102+
SimpleReportEntry firstTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest", "Nested Sample", "test", "Should not be displayed");
103+
WrappedReportEntry wrappedReportEntry1 = new WrappedReportEntry(firstTest, ReportEntryType.SUCCESS, 1, stdout, stderr);
104+
105+
SimpleReportEntry secondTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest", "Nested Sample", "test2", "Should not be displayed");
106+
WrappedReportEntry wrappedReportEntry2 = new WrappedReportEntry(secondTest, ReportEntryType.SUCCESS, 1, stdout, stderr);
107+
108+
SimpleReportEntry thirdTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest", "Inner Test", "test", "Inner failure test should be displayed");
109+
WrappedReportEntry wrappedReportEntry3 = new WrappedReportEntry(thirdTest, ReportEntryType.FAILURE, 1, stdout, stderr);
110+
111+
SimpleReportEntry fourthTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest$InnerInnerTest", "Inner Inner Test", "test", "Inner Inner error test should be displayed");
112+
WrappedReportEntry wrappedReportEntry4 = new WrappedReportEntry(fourthTest, ReportEntryType.ERROR, 1, stdout, stderr);
113+
114+
SimpleReportEntry fifthTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest$InnerInnerTest$InnerInnerInnerTest", "Inner Inner Inner Test", "test", "Inner Inner Inner skipped test should be displayed");
115+
WrappedReportEntry wrappedReportEntry5 = new WrappedReportEntry(fifthTest, ReportEntryType.SKIPPED, 1, stdout, stderr);
116+
117+
SimpleReportEntry sixthTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$FirstInnerTest", "First Inner Test", "test", "FirstInnerTest should not be displayed");
118+
WrappedReportEntry wrappedReportEntry6 = new WrappedReportEntry(sixthTest, ReportEntryType.SUCCESS, 1, stdout, stderr);
119+
120+
TestSetStats testSetStats = new TestSetStats(false, true);
121+
testSetStats.testSucceeded(wrappedReportEntry1);
122+
testSetStats.testSucceeded(wrappedReportEntry2);
123+
testSetStats.testFailure(wrappedReportEntry3);
124+
testSetStats.testError(wrappedReportEntry4);
125+
testSetStats.testSkipped(wrappedReportEntry5);
126+
testSetStats.testSucceeded(wrappedReportEntry6);
127+
128+
TestSetStats testSetStatsForClass = new TestSetStats(false, true);
129+
130+
ReporterOptions optionsHidingSuccess = ReporterOptions.builder().hideResultsOnSuccess(true).build();
131+
ConsoleTreeReporter consoleTreeReporter = new ConsoleTreeReporter(new PluginConsoleLogger(logger), optionsHidingSuccess);
132+
consoleTreeReporter.testSetStarting(simpleReportEntry1);
133+
consoleTreeReporter.testSetStarting(simpleReportEntry2);
134+
consoleTreeReporter.testSetStarting(simpleReportEntry3);
135+
consoleTreeReporter.testSetStarting(simpleReportEntry4);
136+
consoleTreeReporter.testSetCompleted(wrappedReportEntry5, testSetStats, null);
137+
consoleTreeReporter.testSetCompleted(wrappedReportEntry4, testSetStatsForClass, null);
138+
consoleTreeReporter.testSetCompleted(wrappedReportEntry3, testSetStatsForClass, null);
139+
consoleTreeReporter.testSetCompleted(wrappedReportEntry2, testSetStatsForClass, null);
140+
141+
}
142+
143+
93144
}

0 commit comments

Comments
 (0)