@@ -34,17 +34,21 @@ public class Junit5TestListener implements TestExecutionListener {
3434 private final Class <?> testClass ;
3535
3636 // To help give a reasonable (though imprecise) guess at the runtime for unpaired failures
37- private final long startTime = System .currentTimeMillis ();
37+ private long testStartTime ;
38+ private long testPlanStartTime ;
3839
3940 public Junit5TestListener (List <TestResult > results , Level stdErrLogLevel , Level stdOutLogLevel , Class <?> testClass ) {
4041 this .results = results ;
4142 this .stdErrLogLevel = stdErrLogLevel ;
4243 this .stdOutLogLevel = stdOutLogLevel ;
4344 this .testClass = testClass ;
45+ this .testStartTime = System .currentTimeMillis ();
46+ this .testPlanStartTime = System .currentTimeMillis ();
4447 }
4548
4649 @ Override
4750 public void testPlanExecutionStarted (TestPlan testPlan ) {
51+ this .testPlanStartTime = System .currentTimeMillis ();
4852 listener .testPlanExecutionStarted (testPlan );
4953 }
5054
@@ -54,7 +58,7 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
5458 // testStarted was called for latest test, but not the testFinished
5559 // report all failures as unbounded
5660 for (TestExecutionSummary .Failure failure : listener .getSummary ().getFailures ()) {
57- long runtime = System .currentTimeMillis () - startTime ;
61+ long runtime = System .currentTimeMillis () - this . testPlanStartTime ;
5862 String className = testClass .getCanonicalName ();
5963 String methodName = testIdentifier .getDisplayName ().replace ("()" , "" );
6064 results .add (
@@ -81,7 +85,6 @@ public void executionStarted(TestIdentifier testIdentifier) {
8185 if (!testIdentifier .isTest ()) {
8286 return ;
8387 }
84-
8588 // Create an intermediate stdout/stderr to capture any debugging statements (usually in the
8689 // form of System.out.println) the developer is using to debug the test.
8790 originalOut = System .out ;
@@ -111,6 +114,7 @@ public void executionStarted(TestIdentifier testIdentifier) {
111114 julLogHandler = addStreamHandler (rootLogger , julLogBytes , formatter , stdOutLogLevel );
112115 julErrLogHandler = addStreamHandler (rootLogger , julErrLogBytes , formatter , stdErrLogLevel );
113116
117+ this .testStartTime = System .currentTimeMillis ();
114118 listener .executionStarted (testIdentifier );
115119 }
116120
@@ -179,7 +183,7 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
179183
180184 String className = testClass .getCanonicalName ();
181185 String methodName = testIdentifier .getDisplayName ().replace ("()" , "" );
182- long runTime = summary . getTimeFinished () - summary . getTimeStarted () ;
186+ long runTime = System . currentTimeMillis () - this . testStartTime ;
183187 results .add (
184188 new TestResult (
185189 className ,
0 commit comments