Reputation: 1840
All JUnit assert methods have an optional first parameter being the message printed when the assertion fails.
How do I ensure the parameter is always passed, and developers in my project never lazily skip describing what the assertion is doing?
Is there an inspection tool that can check for that? Is there anything I can do programmatically?
My project is maven-friendly.
Upvotes: 1
Views: 892
Reputation: 8044
In our team, we do code reviews of pull requests. If asserts are not following the standard, you could flag it in the review. Only pull requests that have sufficient approvals are allowed to be merged.
That said, I would probably not enforce this rule on my team. Instead I'd tell them to write shorter tests where the method name will clearly state the intent, like:
@Test(expected = IllegalArgumentException.class);
shouldThrowExceptionWhenInputIsNegative() {}
@Test
shouldFilterOutNulls() {}
@Test
shouldCreateAdditionalRecordWhenBankBalanceIsOver10000() {}
etc...
Upvotes: 0
Reputation: 3236
As code inspection seems to be your aim, I would recommend a tool called PMD. If there is not already a rule for this, I would think it is fairly trivial to create one. Furthermore, this will help you in detecting other code mess which your developers may be creating.
Here is a link: http://pmd.sourceforge.net/
Upvotes: 2