2424import org .junit .platform .engine .TestExecutionResult ;
2525import org .junit .platform .engine .support .descriptor .MethodSource ;
2626import org .junit .platform .launcher .TestIdentifier ;
27+ import org .junit .platform .launcher .TestPlan ;
2728import org .junit .platform .launcher .listeners .SummaryGeneratingListener ;
2829
2930import java .util .Arrays ;
3031import java .util .Objects ;
3132
3233public class TestExecutionListener extends SummaryGeneratingListener {
3334
35+ private Long numTests = 0L ;
36+ private Long currentTest = 0L ;
37+
3438 public TestExecutionListener () {
3539
3640 }
3741
42+ @ Override
43+ public void testPlanExecutionStarted (TestPlan testPlan ) {
44+ super .testPlanExecutionStarted (testPlan );
45+
46+ numTests = testPlan .countTestIdentifiers (it -> it .isTest () || (it .isContainer () && it .getUniqueIdObject ().getLastSegment ().getType ().equals ("test-template" )));
47+ }
48+
3849 @ Override
3950 public void executionSkipped (TestIdentifier testIdentifier , String reason ) {
4051 super .executionSkipped (testIdentifier , reason );
4152 if (testIdentifier == null || reason == null || !testIdentifier .isTest ()) return ;
4253
54+ updateCount (testIdentifier );
55+
4356 System .out .println ();
44- System .out .printf ("\t \t --> Skipping test \" %s\" %n" , identifier (testIdentifier ));
57+ System .out .printf ("\t \t --> Skipping test [%s/%s,] \" %s\" %n" , currentTest , numTests , identifier (testIdentifier ));
4558 System .out .println ();
4659 }
4760
@@ -50,8 +63,10 @@ public void executionStarted(TestIdentifier testIdentifier) {
5063 super .executionStarted (testIdentifier );
5164 if (testIdentifier == null || !testIdentifier .isTest ()) return ;
5265
66+ updateCount (testIdentifier );
67+
5368 System .out .println ();
54- System .out .printf ("\t \t --> Started test \" %s\" %n" , identifier (testIdentifier ));
69+ System .out .printf ("\t \t --> Started test [%s/%s] \" %s\" %n" , currentTest , numTests , identifier (testIdentifier ));
5570 System .out .println ();
5671 }
5772
@@ -61,7 +76,7 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
6176 if (testIdentifier == null || testExecutionResult == null || !testIdentifier .isTest ()) return ;
6277
6378 System .out .println ();
64- System .out .printf ("\t \t --> Finished test \" %s\" : %s%n" , identifier (testIdentifier ), testExecutionResult );
79+ System .out .printf ("\t \t --> Finished test [%s/%s] \" %s\" : %s%n" , currentTest , numTests , identifier (testIdentifier ), testExecutionResult );
6580 System .out .println ();
6681 }
6782
@@ -77,4 +92,17 @@ private String identifier(TestIdentifier testIdentifier) {
7792 }
7893 return String .format ("%s %s" , className , methodSource .getMethodName ());
7994 }
95+
96+ private void updateCount (TestIdentifier testIdentifier ) {
97+ if (testIdentifier .getUniqueIdObject ().getLastSegment ().getType ().equals ("test-template-invocation" )) {
98+ int c = Integer .parseInt (testIdentifier .getUniqueIdObject ().getLastSegment ().getValue ().replace ("#" , "" ));
99+ if (c > 1 ) {
100+ // update total count if it's a template (instances of templates are not included in the initial total)
101+ numTests ++;
102+ }
103+ }
104+
105+ currentTest ++;
106+ }
107+
80108}
0 commit comments