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

assertFailsWith<SomeExceptionType> { ... } #511

Open
swankjesse opened this issue Jan 6, 2024 · 0 comments
Open

assertFailsWith<SomeExceptionType> { ... } #511

swankjesse opened this issue Jan 6, 2024 · 0 comments

Comments

@swankjesse
Copy link

This PR migrated about 500 exception tests in OkHttp from this form:

try {
  doThing()
  fail()
} catch (expected: SomeSpecificExceptionType) {
}

to this form:

assertFailsWith<SomeSpecificExceptionType> {
  doThing()
}

I had to use kotlin.test’s assertFailsWith() even though I generally prefer assertk’s APIs, because assertk doesn’t have a function that lets me expect a failure of a specific type in one go.

I know I could have done this:

assertFailure {
  doThing()
}.isInstanceOf<SomeSpecificExceptionType>()

But it’s more code, and I’m in the code deleting business.

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

1 participant