Skip to content

Commit b38b483

Browse files
committed
ensure @RobolectricTest can't be silently skipped
It seems Kotest's intercept caller eats expections and moves on silently. Adding a try-catch and reporting TestResult.Error to solve this.
1 parent 6ddcaf9 commit b38b483

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/extensions/RobolectricExtension.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.kotest.core.test.TestResult
1616
import org.robolectric.annotation.Config
1717
import kotlin.reflect.KClass
1818
import kotlin.reflect.full.findAnnotation
19+
import kotlin.time.Duration
1920

2021
/**
2122
* We override TestCaseExtension to configure the Robolectric environment because TestCase intercept
@@ -62,6 +63,19 @@ internal class RobolectricExtension : ConstructorExtension, TestCaseExtension {
6263
override suspend fun intercept(
6364
testCase: TestCase,
6465
execute: suspend (TestCase) -> TestResult,
66+
): TestResult {
67+
return try {
68+
runTest(testCase, execute)
69+
} catch (t: Throwable) {
70+
// Without this the whole test class will be silently be skipped
71+
// if something throws
72+
TestResult.Error(Duration.ZERO, t)
73+
}
74+
}
75+
76+
private suspend fun runTest(
77+
testCase: TestCase,
78+
execute: suspend (TestCase) -> TestResult,
6579
): TestResult {
6680
// FIXED: Updated code based on https://github.com/kotest/kotest/issues/2717
6781
val hasRobolectricAnnotation =

0 commit comments

Comments
 (0)