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

Show warning for assertTrue(xxx instanceof SomeClass) in junit tests #390

Closed
trancexpress opened this issue Sep 21, 2017 · 3 comments
Closed

Comments

@trancexpress
Copy link
Contributor

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.

@trancexpress
Copy link
Contributor Author

Please add enhancement label as I'm not able to do so.

@WarpspeedSCP
Copy link
Contributor

I'd like to implement a detector for this.

@KengoTODA, should I do a pr to fb-contrib or to spotbugs for this?

@KengoTODA
Copy link
Member

Both of them are OK. If you want to run your detector with FindBugs or old SpotBugs, fb-contrib will be a good choice.

@WarpspeedSCP WarpspeedSCP mentioned this issue Aug 14, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants