Skip to content

Commit

Permalink
Try this way.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmonz committed Nov 27, 2024
1 parent e1a1041 commit dd79115
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class JUnit5Listener : TestExecutionListener {
accumulateResultsOfEachTest(testExecutionResult)

override fun testPlanExecutionFinished(testPlan: TestPlan) =
updateTimestampIfAndOnlyIfAllTestsPass()
updateTimestampIfAndOnlyIfAllTestsPass(testPlan)

private fun accumulateResultsOfEachTest(testExecutionResult: TestExecutionResult) {
if (testExecutionResult.status == SUCCESSFUL) {
Expand All @@ -27,17 +27,15 @@ class JUnit5Listener : TestExecutionListener {
}
}

private fun updateTimestampIfAndOnlyIfAllTestsPass() {
private fun updateTimestampIfAndOnlyIfAllTestsPass(testPlan: TestPlan) {
if (System.getenv("GREENCENTLY_SUMMARY") !== null) {
System.err.println(
"greencently (total, green, red): " +
"(${greenTestCount + redTestCount}, $greenTestCount, $redTestCount)"
"greencently (green, red): ($greenTestCount, $redTestCount)"
)
}

val expectedTestCount = JUnit5Planner(null).getTestCount()
val expected = JUnit5Summary(expectedTestCount, expectedTestCount, 0)
val actual = JUnit5Summary(greenTestCount + redTestCount, greenTestCount, redTestCount)
val expected = JUnit5Summary(JUnit5Planner(null).prepareTestPlan(), 0, 0)
val actual = JUnit5Summary(testPlan, greenTestCount, redTestCount)
if (actual == expected) Timestamp("junit5").setToNow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.schmonz.greencently.planner

import org.junit.platform.engine.discovery.ClassNameFilter
import org.junit.platform.engine.discovery.DiscoverySelectors
import org.junit.platform.launcher.TestIdentifier
import org.junit.platform.launcher.TestPlan
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder
import org.junit.platform.launcher.core.LauncherFactory
import java.nio.file.Path
Expand All @@ -27,7 +27,7 @@ class JUnit5Planner(testClasspath: Path?, private val testClassesMatching: Strin
private fun isGradleOutputClasspath(path: String) =
path.endsWith("/test")

fun getTestCount(): Long =
fun prepareTestPlan(): TestPlan =
LauncherFactory
.create()
.discover(
Expand All @@ -37,5 +37,4 @@ class JUnit5Planner(testClasspath: Path?, private val testClassesMatching: Strin
.filters(ClassNameFilter.includeClassNamePatterns(testClassesMatching))
.build()
)
.countTestIdentifiers(TestIdentifier::isTest)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.schmonz.greencently.summary

import org.junit.platform.launcher.TestIdentifier
import org.junit.platform.launcher.TestPlan
import java.util.Objects

class JUnit5Summary(internal val testCount: Long, internal val greenTestCount: Long, internal val redTestCount: Long) {
class JUnit5Summary(testPlan: TestPlan, internal val greenTestCount: Long, internal val redTestCount: Long) {
internal val testCount = testPlan.countTestIdentifiers(TestIdentifier::isTest)

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is JUnit5Summary) return false
Expand Down

0 comments on commit dd79115

Please sign in to comment.