Even if some rule engine like PMD or Checkstyle has dedicated rules to analyse unit test source code, Sonar doesn't integrate those rules (http://pmd.sourceforge.net/rules/junit.html) and doesn't provide any feature to check the quality of unit test source code.
Of course, most of the time the quality requirements on unit test source code are not the same than the quality requirements on main source code.
here is an exemple of a rule set for unit test source code :
- no if/else logic per unit-test
- clear setup/excercise/assert order (no verify() before when() speaking of
- disallow reflection to hack-test private methods
Sonar should allow to activate some rules :
- only on unit test source code
- only on main source code
- both on unit test and main source code
I guess a new column must be added to the rules and active_rules tables to handle such options. Moreover, Sonar should be able to launch rule engines like PMD to analyse the unit test source code with a subset of all the rules contained in the quality profile of the project.