-
Notifications
You must be signed in to change notification settings - Fork 586
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
Show warning for assertTrue(xxx instanceof SomeClass) in junit tests #390
Labels
Comments
Please add enhancement label as I'm not able to do so. |
I'd like to implement a detector for this. @KengoTODA, should I do a pr to fb-contrib or to spotbugs for this? |
Both of them are OK. If you want to run your detector with FindBugs or old SpotBugs, fb-contrib will be a good choice. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I run into numerous tests which make assumptions for specific types of objects by casting to that type. Before a lot of those casts, an
assertTrue
is used to validate that the assumption is correct.This assertion however is far less verbose than the class cast exception that would occur without the assertion. Namely, when the assertion fails it will state that false is not true. As opposed to class XXX cannot be casted to ZZZ, without the assertion. In some cases, such as very sporadic test failures, the actual type of the object can give vital clues for the nature of the fail.
It would be great if a warning issue is shown on the line, explaining why such assertions are not a good practice in tests.
The text was updated successfully, but these errors were encountered: