-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Should handle throwables as failed tests #20
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 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
36 changes: 36 additions & 0 deletions
36
src/test/kotlin/io/kotlintest/KotlinTestJunitRunnerTest.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,36 @@ | ||
package io.kotlintest | ||
|
||
import io.kotlintest.specs.ShouldSpec | ||
import org.junit.runner.notification.Failure | ||
import org.junit.runner.notification.RunListener | ||
import org.junit.runner.notification.RunNotifier | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
class KotlinTestJunitRunnerTest : ShouldSpec() { | ||
init { | ||
should("handle throwables") { | ||
System.setProperty("internal", "true") | ||
val runner = KTestJUnitRunner(ThrowsThrowable::class.java as Class<TestBase>) | ||
val n = RunNotifier() | ||
val latch = CountDownLatch(1) | ||
n.addListener(object : RunListener() { | ||
override fun testFailure(failure: Failure?) { | ||
latch.countDown() | ||
} | ||
}) | ||
runner.run(n) | ||
latch.await(5, TimeUnit.SECONDS) shouldBe true | ||
System.setProperty("internal", "false") | ||
} | ||
} | ||
} | ||
|
||
class ThrowsThrowable : ShouldSpec() { | ||
init { | ||
should("throw throwable") { | ||
if (System.getProperty("internal") == "true") | ||
throw Throwable("hello") | ||
} | ||
} | ||
} |