Skip to content

Commit

Permalink
Should handle throwables as failed tests #20
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed May 28, 2016
1 parent 2864eff commit 4046fe8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/io/kotlintest/KTestJUnitRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class KTestJUnitRunner(val testClass: Class<TestBase>) : Runner() {
instance2.beforeEach()
notifier.fireTestStarted(desc)
testcase.test()
} catch(e: Exception) {
} catch(e: Throwable) {
notifier.fireTestFailure(Failure(desc, e))
} finally {
notifier.fireTestFinished(desc)
Expand All @@ -42,7 +42,7 @@ class KTestJUnitRunner(val testClass: Class<TestBase>) : Runner() {
notifier.fireTestStarted(desc)
instance.beforeEach()
testcase.test()
} catch(e: Exception) {
} catch(e: Throwable) {
notifier.fireTestFailure(Failure(desc, e))
} finally {
notifier.fireTestFinished(desc)
Expand Down
36 changes: 36 additions & 0 deletions src/test/kotlin/io/kotlintest/KotlinTestJunitRunnerTest.kt
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")
}
}
}

0 comments on commit 4046fe8

Please sign in to comment.