-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding JVM SpecInterceptor reclassifying aborted tests as Ignored (#3268
) * Adding JVM SpecInterceptor reclassifying aborted tests as Ignored * Adding tests for TestResult.Success and TestResult.Failure
- Loading branch information
Showing
7 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...mework/kotest-framework-engine/src/commonMain/kotlin/io/kotest/engine/SpecInterceptors.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.kotest.engine | ||
|
||
import io.kotest.common.KotestInternal | ||
import io.kotest.engine.spec.interceptor.SpecInterceptor | ||
|
||
/** | ||
* Returns the [SpecInterceptor]s that should be used for this platform. | ||
*/ | ||
@KotestInternal | ||
internal expect fun specInterceptorsForPlatform(): List<SpecInterceptor> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ain/kotlin/io/kotest/engine/interceptors/MarkAbortedExceptionsAsSkippedTestInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.kotest.engine.interceptors | ||
|
||
import io.kotest.common.JVMOnly | ||
import io.kotest.common.KotestInternal | ||
import io.kotest.core.spec.Spec | ||
import io.kotest.core.test.TestCase | ||
import io.kotest.core.test.TestResult | ||
import io.kotest.engine.spec.interceptor.SpecInterceptor | ||
import org.opentest4j.TestAbortedException | ||
|
||
/** | ||
* Writes failed specs to a file so that the [io.kotest.engine.spec.FailureFirstSorter] | ||
* can use the file to run failed specs first. | ||
* | ||
* Note: This is a JVM only feature. | ||
*/ | ||
@JVMOnly | ||
internal object MarkAbortedExceptionsAsSkippedTestInterceptor : SpecInterceptor { | ||
|
||
override suspend fun intercept( | ||
spec: Spec, | ||
fn: suspend (Spec) -> Result<Map<TestCase, TestResult>> | ||
): Result<Map<TestCase, TestResult>> { | ||
return fn(spec).map { success -> | ||
success.mapValues { (_, result) -> | ||
if (result.errorOrNull is TestAbortedException) { | ||
TestResult.Ignored | ||
} else { | ||
result | ||
} | ||
} | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...engine/src/jvmTest/kotlin/com/sksamuel/kotest/engine/interceptors/AbortedExceptionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.sksamuel.kotest.engine.interceptors | ||
|
||
import io.kotest.core.descriptors.Descriptor | ||
import io.kotest.core.descriptors.DescriptorId | ||
import io.kotest.core.names.TestName | ||
import io.kotest.core.spec.style.FreeSpec | ||
import io.kotest.core.test.TestCase | ||
import io.kotest.core.test.TestResult | ||
import io.kotest.core.test.TestType | ||
import io.kotest.engine.interceptors.MarkAbortedExceptionsAsSkippedTestInterceptor | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.result.shouldBeSuccess | ||
import org.opentest4j.TestAbortedException | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
class AbortedExceptionTest : FreeSpec({ | ||
|
||
val fakeTestCase = TestCase( | ||
Descriptor.TestDescriptor( | ||
Descriptor.SpecDescriptor(DescriptorId("dummy"), DummySpec::class), | ||
DescriptorId("test") | ||
), TestName("dummy"), DummySpec(), {}, type = TestType.Test | ||
) | ||
|
||
"Test should be marked as Ignored" { | ||
val result = MarkAbortedExceptionsAsSkippedTestInterceptor.intercept(DummySpec()) { | ||
Result.success( | ||
mapOf(fakeTestCase to TestResult.Error(1.milliseconds, TestAbortedException())) | ||
) | ||
} | ||
|
||
result.shouldBeSuccess() | ||
.values | ||
.shouldContainExactly(TestResult.Ignored) | ||
} | ||
|
||
"Failure is not reclassified" { | ||
val assertionError = AssertionError("blah") | ||
val result = MarkAbortedExceptionsAsSkippedTestInterceptor.intercept(DummySpec()) { | ||
Result.success( | ||
mapOf(fakeTestCase to TestResult.Failure(1.milliseconds, assertionError)) | ||
) | ||
} | ||
|
||
result.shouldBeSuccess() | ||
.values | ||
.shouldContainExactly(TestResult.Failure(1.milliseconds, assertionError)) | ||
} | ||
|
||
"Successful test is not reclassified" { | ||
val result = MarkAbortedExceptionsAsSkippedTestInterceptor.intercept(DummySpec()) { | ||
Result.success( | ||
mapOf(fakeTestCase to TestResult.Success(1.milliseconds)) | ||
) | ||
} | ||
|
||
result.shouldBeSuccess() | ||
.values | ||
.shouldContainExactly(TestResult.Success(1.milliseconds)) | ||
} | ||
}) | ||
|
||
private class DummySpec : FreeSpec() | ||
|