-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing TestAbortedException not being marked as Ignored (#3587)
Co-authored-by: Sam <sam@sksamuel.com>
- Loading branch information
Showing
7 changed files
with
72 additions
and
52 deletions.
There are no files selected for viewing
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
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
73 changes: 36 additions & 37 deletions
73
...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 |
---|---|---|
@@ -1,64 +1,63 @@ | ||
package com.sksamuel.kotest.engine.interceptors | ||
|
||
import io.kotest.assertions.fail | ||
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.TestEngineLauncher | ||
import io.kotest.engine.interceptors.MarkAbortedExceptionsAsSkippedTestInterceptor | ||
import io.kotest.engine.listener.CollectingTestEngineListener | ||
import io.kotest.inspectors.forOne | ||
import io.kotest.matchers.booleans.shouldBeTrue | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.collections.shouldMatchEach | ||
import io.kotest.matchers.maps.shouldContainAll | ||
import io.kotest.matchers.maps.shouldMatchAll | ||
import io.kotest.matchers.result.shouldBeSuccess | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.types.shouldBeInstanceOf | ||
import org.opentest4j.TestAbortedException | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
class AbortedExceptionTest : FreeSpec({ | ||
"TestAbortedException is handled" { | ||
val collector = CollectingTestEngineListener() | ||
|
||
TestEngineLauncher(collector) | ||
.withClasses(DummySpec::class) | ||
.launch() | ||
|
||
collector.tests.toList().shouldMatchEach( | ||
{ | ||
it.first.name.testName shouldBe "Test should be marked as Ignored" | ||
it.second.isIgnored.shouldBeTrue() | ||
}, | ||
{ | ||
it.first.name.testName shouldBe "Failure is not reclassified" | ||
it.second.isFailure.shouldBeTrue() | ||
}, | ||
{ | ||
it.first.name.testName shouldBe "Successful test is not reclassified" | ||
it.second.isSuccess.shouldBeTrue() | ||
} | ||
) | ||
} | ||
}) | ||
|
||
val fakeTestCase = TestCase( | ||
Descriptor.TestDescriptor( | ||
Descriptor.SpecDescriptor(DescriptorId("dummy"), DummySpec::class), | ||
DescriptorId("test") | ||
), TestName("dummy"), DummySpec(), {}, type = TestType.Test | ||
) | ||
|
||
private class DummySpec : FreeSpec({ | ||
"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) | ||
throw TestAbortedException() | ||
} | ||
|
||
"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)) | ||
fail("should not be ignored") | ||
} | ||
|
||
"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() | ||
|