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

ExpectedException for AnnotationSpec #527

Closed
LeoColman opened this issue Jan 7, 2019 · 1 comment
Closed

ExpectedException for AnnotationSpec #527

LeoColman opened this issue Jan 7, 2019 · 1 comment
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.
Milestone

Comments

@LeoColman
Copy link
Member

LeoColman commented Jan 7, 2019

In the same line of #522, JUnit has a parameter in @Test called expected
This parameter verifies that the test threw an Exception or a subclass of it.

For example:

@Test(expected = FooException::class)
fun foo() {
    throw FooException() // Test passes
}

@Test(expected = BarException::class)
fun bar() {
    println("Bar?")  // Test fails, BarException wasn't thrown
}

Should we also support it?

@LeoColman LeoColman added the enhancement ✨ Suggestions for adding new features or improving existing ones. label Jan 7, 2019
@sksamuel
Copy link
Member

sksamuel commented Jan 7, 2019 via email

@LeoColman LeoColman added this to the 3.3 milestone Jan 11, 2019
LeoColman added a commit that referenced this issue Jan 14, 2019
JUnit's tests can test an exception is thrown by using a parameter in the `@Test` annotation. https://github.com/junit-team/junit4/wiki/exception-testing

Although we support `shouldThrow` and it's variants, we're trying to improve the likelihood of people using KotlinTest instead of JUnit, by making the migration as easy as possible. Because of this objective, this commit implements a parameter in `@Test`, to enable users to configure an expected exception just like JUnit's.

To do this, this commit creates the parameter and annotation processing for it.

To reuse code, this commit moves some internal classes around, to enable `kotlintest-core` module to use some of the classes from `kotlintest-assertions` and `kotlintest-runner-jvm`. This doesn't impact any user, as the moved classes and functions are internal/private.

To test that the new behavior works, this commit uses `SpecLevelExtension` to map specific tests with specific behaviors. It's not very pretty, but it works.

Fixes #527
@LeoColman LeoColman changed the title @Expected for AnnotationSpec ExpectedException for AnnotationSpec Jan 14, 2019
LeoColman added a commit that referenced this issue Jan 14, 2019
JUnit's tests can test an exception is thrown by using a parameter in the `@Test` annotation. https://github.com/junit-team/junit4/wiki/exception-testing

Although we support `shouldThrow` and it's variants, we're trying to improve the likelihood of people using KotlinTest instead of JUnit, by making the migration as easy as possible. Because of this objective, this commit implements a parameter in `@Test`, to enable users to configure an expected exception just like JUnit's.

To do this, this commit creates the parameter and annotation processing for it.

To reuse code, this commit copies some internal classes around, to enable `kotlintest-core` module to use some of the classes from `kotlintest-assertions` and `kotlintest-runner-jvm`. This doesn't impact any user, as the classes were copied. However, they're marked for deletion soon-ish.

To test that the new behavior works, this commit uses `SpecLevelExtension` to map specific tests with specific behaviors. It's not very pretty, but it works.

Fixes #527
LeoColman added a commit that referenced this issue Jan 15, 2019
JUnit's tests can test an exception is thrown by using a parameter in the `@Test` annotation. https://github.com/junit-team/junit4/wiki/exception-testing

Although we support `shouldThrow` and it's variants, we're trying to improve the likelihood of people using KotlinTest instead of JUnit, by making the migration as easy as possible. Because of this objective, this commit implements a parameter in `@Test`, to enable users to configure an expected exception just like JUnit's.

To do this, this commit creates the parameter and annotation processing for it.

To reuse code, this commit copies some internal classes around, to enable `kotlintest-core` module to use some of the classes from `kotlintest-assertions` and `kotlintest-runner-jvm`. This doesn't impact any user, as the classes were copied. However, they're marked for deletion soon-ish.

To test that the new behavior works, this commit uses `SpecLevelExtension` to map specific tests with specific behaviors. It's not very pretty, but it works.

Fixes #527
@sksamuel sksamuel mentioned this issue Jan 30, 2019
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.
Projects
None yet
Development

No branches or pull requests

2 participants