-
Notifications
You must be signed in to change notification settings - Fork 260
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
Include assertThrows
into core api
#621
Comments
Just piping up to point out that this is slightly different than previous discussions about While I think it kind of made sense before when we were certain everyone would have this (or equivalent) function in their deps, I don't think that's a sound assumption under present conditions. (Trying to head off objections that I've already heard inside Google to related inquiries, since I think we're in a different situation than that in which those discussions occurred) |
related: b/114409026 |
The linked API is notably different (and more usable, not that I'm biased as its author) than JUnit and kotlin.test. In Kotlin, for JUnit, you have to use Beyond that, the other APIs immediately fall short. JUnit lets you assert on the exact message but nothing like start/end/regex-based matching. For that, you need to change how you assert by capturing the return value and asserting on the message or wrapping in a Similarly, any causal analysis requires capturing the The above snippet returns the assertThrows<IllegalStateException> {
...
}.apply {
hasMessage().startsWith("Whatever: ")
hasCause().isInstanceOf(SomeException::class.java)
} |
I really do like @JakeWharton's variant, but I'm not sure if this can be achieved from within Java, so there are a few things questions this forces.
Personally I'd love to see Jake's flavor, but we also have a lot of Java left. |
Is this issue here about Kotlin only? From the title of this issue it sounds to be generic, but the comments here seem to be mostly / only about Kotlin. Even for Java projects a Truth
Maybe it would also be useful to have two flavors: One |
Yes, I'm not keen to add a JUnit dependency just for I'm currently using (Java): try {
[Manipulate object "o"]
assertWithMessage("Manipulating %s should have thrown an UnsupportedOperationException", o).fail();
} catch (UnsupportedOperationException expected) {} |
We'd like to use this code aosp-mirror/platform_frameworks_support@bf04c31#diff-46afb720089a0149afb46f71274f5642 from our Kotlin tests, can you please include it into Truth?
We could just add it to one of our internal libraries and use it. However, seeing as this code is being duplicated on many repos on GitHub: https://github.com/search?l=Kotlin&p=2&q=ThrowableSubject&type=Code, it might make sense to include it in Truth.
The text was updated successfully, but these errors were encountered: