From 3c91d059933dc1dfca698e83f9f9a38774b91d98 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Mon, 8 May 2023 10:42:50 +0100 Subject: [PATCH 1/2] Fix nested tests where only the last nested test was printed --- .../apache/maven/plugin/surefire/report/TestReportHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugin/surefire/report/TestReportHandler.java b/src/main/java/org/apache/maven/plugin/surefire/report/TestReportHandler.java index c804c64..fc3d504 100644 --- a/src/main/java/org/apache/maven/plugin/surefire/report/TestReportHandler.java +++ b/src/main/java/org/apache/maven/plugin/surefire/report/TestReportHandler.java @@ -68,7 +68,7 @@ private Set getClassNameList() { } private void prepareTestEntriesForNestedTest() { - testEntries.putIfAbsent(sourceRootName, new ArrayList<>(testSetStats.getReportEntries())); + testEntries.computeIfAbsent(sourceRootName, $ -> new ArrayList<>()).addAll(testSetStats.getReportEntries()); } private List getTestEntryList() { From 9ae691537b95b5c58b48e7a84b201d3646aff0ea Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Mon, 8 May 2023 10:54:49 +0100 Subject: [PATCH 2/2] Add another nested test to the tests --- src/test/java/NestedExampleTest.java | 10 ++++++++++ .../surefire/report/ConsoleTreeReporterTest.java | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/java/NestedExampleTest.java b/src/test/java/NestedExampleTest.java index c175662..c6b20c1 100644 --- a/src/test/java/NestedExampleTest.java +++ b/src/test/java/NestedExampleTest.java @@ -11,6 +11,16 @@ void test() throws InterruptedException { Thread.sleep(100); } + @Nested + @DisplayName("First Inner Test") + class FirstInnerTest { + @Test + @DisplayName("FirstInnerTest should show up") + void test() throws InterruptedException { + Thread.sleep(100); + } + } + @Nested @DisplayName("Inner Test") class InnerTest { diff --git a/src/test/java/org/apache/maven/plugin/surefire/report/ConsoleTreeReporterTest.java b/src/test/java/org/apache/maven/plugin/surefire/report/ConsoleTreeReporterTest.java index 37b120d..2d40815 100644 --- a/src/test/java/org/apache/maven/plugin/surefire/report/ConsoleTreeReporterTest.java +++ b/src/test/java/org/apache/maven/plugin/surefire/report/ConsoleTreeReporterTest.java @@ -58,12 +58,14 @@ void testSetCompleted() { SimpleReportEntry thirdTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest", "Inner Test", "test", "Inner test should pass"); SimpleReportEntry fourthTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest$InnerInnerTest", "Inner Inner Test", "test", "Inner Inner Test should pass"); SimpleReportEntry fifthTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$InnerTest$InnerInnerTest$InnerInnerInnerTest", "Inner Inner Inner Test", "test", "Inner Inner Inner Test should pass"); + SimpleReportEntry sixthTest = new SimpleReportEntry(RunMode.NORMAL_RUN, 123L, "NestedExampleTest$FirstInnerTest", "First Inner Test", "test", "FirstInnerTest should show up"); WrappedReportEntry wrappedReportEntry1 = new WrappedReportEntry(firstTest, ReportEntryType.SUCCESS, 1, stdout, stderr); WrappedReportEntry wrappedReportEntry2 = new WrappedReportEntry(secondTest, ReportEntryType.SUCCESS, 1, stdout, stderr); WrappedReportEntry wrappedReportEntry3 = new WrappedReportEntry(thirdTest, ReportEntryType.SUCCESS, 1, stdout, stderr); WrappedReportEntry wrappedReportEntry4 = new WrappedReportEntry(fourthTest, ReportEntryType.SUCCESS, 1, stdout, stderr); WrappedReportEntry wrappedReportEntry5 = new WrappedReportEntry(fifthTest, ReportEntryType.SUCCESS, 1, stdout, stderr); + WrappedReportEntry wrappedReportEntry6 = new WrappedReportEntry(sixthTest, ReportEntryType.SUCCESS, 1, stdout, stderr); TestSetStats testSetStats = new TestSetStats(false, true); testSetStats.testSucceeded(wrappedReportEntry1); @@ -71,6 +73,7 @@ void testSetCompleted() { testSetStats.testSucceeded(wrappedReportEntry3); testSetStats.testSucceeded(wrappedReportEntry4); testSetStats.testSucceeded(wrappedReportEntry5); + testSetStats.testSucceeded(wrappedReportEntry6); TestSetStats testSetStatsForClass = new TestSetStats(false, true); @@ -87,4 +90,4 @@ void testSetCompleted() { //TODO see how to unit test this } -} \ No newline at end of file +}