fabriciorby/maven-surefire-junit5-tree-reporter

Get elapsed time reported correctly for @Nested tests

Closed this issue · 3 comments

BTW, the time reported is still not correct because of a reverse order of events the surefire plugin is sending to the ReportConsole

here's an example:

public class NestedWaitingTest {
@Test
public void outside() throws InterruptedException {
    Thread.sleep(1000);
}
@Nested
class Inside1Test {
    @Test
    public void inside1() throws InterruptedException {
        System.out.println("Waiting for 3 seconds");
        Thread.sleep(3000);
    }
    @Test
    public void inside1fast() {
    }

    @Nested
    class Inside2Test {
        @Test
        public void inside2fast() {
        }
    }
}
}

you get this report (without plugin)
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 s - in NestedWaitingTest$Inside1Test$Inside2Test
[INFO] NestedWaitingTest.outside Time elapsed: 1.019 s
[INFO] NestedWaitingTest$Inside1Test.inside1fast Time elapsed: 0.001 s
[INFO] NestedWaitingTest$Inside1Test.inside1 Time elapsed: 3.007 s
[INFO] NestedWaitingTest$Inside1Test$Inside2Test.inside2fast Time elapsed: 0.001 s
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.021 s - in NestedWaitingTest$Inside1Test
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.053 s - in NestedWaitingTest

this translate into 3 events coming into ConsoleReporter
1st one you use today to print the entire data (includes 4 entires in the TreeSetStats) - but uses the elapsed time of the inner*2 test class
2nd and 3rd event are coming without any entries in the TreeSetStats but with correct elapsed time information

so if you want to be consistent with the elapsed time, you need to implement a different approach

Originally posted by @avishayh in #21 (comment)

Ticket created: https://issues.apache.org/jira/browse/SUREFIRE-2111

There is no way of getting other events within the same event