@@ -22,11 +22,15 @@ package eu.openanalytics.shinyproxyoperator.helpers.junit
2222
2323import org.junit.platform.engine.TestExecutionResult
2424import org.junit.platform.launcher.TestIdentifier
25+ import org.junit.platform.launcher.TestPlan
2526import org.junit.platform.launcher.listeners.SummaryGeneratingListener
2627import java.io.PrintWriter
2728
2829class TestExecutionListener : SummaryGeneratingListener () {
2930
31+ private var numTests: Long = 0
32+ private var currentTest: Long = 0
33+
3034 init {
3135 Runtime .getRuntime().addShutdownHook(Thread {
3236 if (summary != null ) {
@@ -35,21 +39,33 @@ class TestExecutionListener : SummaryGeneratingListener() {
3539 })
3640 }
3741
42+ override fun testPlanExecutionStarted (testPlan : TestPlan ) {
43+ super .testPlanExecutionStarted(testPlan)
44+
45+ numTests = testPlan.countTestIdentifiers { it.isTest || (it.isContainer && it.uniqueIdObject.lastSegment.type == " test-template" ) }
46+ }
47+
3848 override fun executionSkipped (testIdentifier : TestIdentifier ? , reason : String? ) {
3949 super .executionSkipped(testIdentifier, reason)
4050 if (testIdentifier == null || reason == null || ! testIdentifier.isTest) return
4151
52+ updateCount(testIdentifier)
53+
4254 println ()
43- println (" \t\t --> Skipping test \" ${testIdentifier.displayName} \" " )
55+ println (" \t\t --> Skipping test [ $currentTest / $numTests ] \" ${testIdentifier.displayName} \" " )
4456 println ()
4557 }
4658
4759 override fun executionStarted (testIdentifier : TestIdentifier ? ) {
4860 super .executionStarted(testIdentifier)
49- if (testIdentifier == null || ! testIdentifier.isTest) return
61+ if (testIdentifier == null || ! testIdentifier.isTest) {
62+ return
63+ }
64+
65+ updateCount(testIdentifier)
5066
5167 println ()
52- println (" \t\t --> Started test \" ${testIdentifier.displayName} \" " )
68+ println (" \t\t --> Started test [ $currentTest / $numTests ] \" ${testIdentifier.displayName} \" " )
5369 println ()
5470 }
5571
@@ -58,7 +74,7 @@ class TestExecutionListener : SummaryGeneratingListener() {
5874 if (testIdentifier == null || testExecutionResult == null || ! testIdentifier.isTest) return
5975
6076 println ()
61- println (" \t\t --> Finished test \" ${testIdentifier.displayName} \" : $testExecutionResult " )
77+ println (" \t\t --> Finished test [ $currentTest / $numTests ] \" ${testIdentifier.displayName} \" : $testExecutionResult " )
6278 if (testExecutionResult.throwable.isPresent) {
6379 println ()
6480 print (" \t\t --> " )
@@ -67,4 +83,16 @@ class TestExecutionListener : SummaryGeneratingListener() {
6783 println ()
6884 }
6985
86+ private fun updateCount (testIdentifier : TestIdentifier ) {
87+ if (testIdentifier.uniqueIdObject?.lastSegment?.type == " test-template-invocation" ) {
88+ val c = testIdentifier.uniqueIdObject?.lastSegment?.value?.replace(" #" , " " )?.toIntOrNull() ? : return
89+ if (c > 1 ) {
90+ // update total count if it's a template (instances of templates are not included in the initial total)
91+ numTests++
92+ }
93+ }
94+
95+ currentTest++
96+ }
97+
7098}
0 commit comments