A very suitable approach is:
to have one checkStyle rule set for src code and another for test.
In eclipse you can configure that in Project->Properties->Checkstyle.
Checkstyle rules for src are not always suitable for test code, like shown by the OP in the example above. Other candidate rules to disable in test would be The MagicNumber check.
If you have the need to disable one or more checks for the next N lines in src,
you should configure: (see also http://checkstyle.sourceforge.net/config.html)
To configure a filter so that CHECKSTYLE IGNORE check FOR NEXT var
LINES avoids triggering any audits for the given check for the current
line and the next var lines (for a total of var+1 lines):
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="CHECKSTYLE IGNORE (\w+) FOR NEXT (\d+) LINES"/>
<property name="checkFormat" value="$1"/>
<property name="influenceFormat" value="$2"/> </module>
Then in your src or test code you can disable specific Checkstyle rules with
/**
* Tests worker1.
*/
//CHECKSTYLE IGNORE <Rule> 1
public void testWorker1() throws Exception {
}
Where "Rule" is the name of the rule, look that up in the link above.
For ignoring line length limitaion to 80 char, for th enext 10 lines the comment would be
//CHECKSTYLE IGNORE Line 100
Your further can concatenate rules :
//CHECKSTYLE IGNORE Line|MethodLength 100
And if you are a very serious developper you fruther could add a comment why you do this:
//CHECKSTYLE IGNORE Catch 1 Last line of defense: need to catch Exception