Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle expected exception #89

Closed
pilgr opened this issue Jun 6, 2016 · 3 comments
Closed

Handle expected exception #89

pilgr opened this issue Jun 6, 2016 · 3 comments

Comments

@pilgr
Copy link

pilgr commented Jun 6, 2016

Is it possible to write tests where specific exception is expected, like using @Test(expected = UnhandledException::class) from JUnit ?
Thanks!

@artem-zinnatullin
Copy link
Collaborator

For now you definitely can use plain try/catch check inside of it {}

@raniejade
Copy link
Member

If you use https://github.com/npryce/hamkrest you can do:

assertThat({throw ExampleException("testing")}, throws<ExampleException>())
// negation
assertThat({ /* do something */ }, !throws<Throwable>())

@mfulton26
Copy link

One of Spek's transitive dependencies is kotlin-test which has assertFails and assertFailsWith:

assertFailsWith<IllegalStateException> { 
    check(false)
}

See kotlin/kotlin/test/TestAssertions.kt and kotlin.jvm/kotlin/test/TestAssertionsJVM.kt.

@hhariri hhariri closed this as completed Sep 1, 2016
encodeering added a commit to encodeering/conflate that referenced this issue Feb 12, 2017
* following a suggestion from kotlin test with a reified syntax

NOTE

* spekframework/spek#89
encodeering added a commit to encodeering/conflate that referenced this issue Feb 13, 2017
* following a suggestion from kotlin test with a reified syntax

NOTE

* spekframework/spek#89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants