Hi,
I just upgraded to SonarQube 10.6 and I’m seeing the rule S1130 being reported on most of my test methods when no Exception is thrown.
I perfectly understand the rule for the main code but I think this is a really common development pattern to always add throws Exception
to test methods.
Considering this rule, I should remove the throw declaration. But if some day in the future, a tested method declares throwing a checked Exception, I should modify all my test code to declare the throw even if the test code is not impacted by the change.
I suppose you should only be required to change your tests to add (or modify) the new test case(s).
I don’t know for other IDEs but the code templates for junit3, junit4 and junit5 tests/tests factories in Eclipse adds throws Exception
to every method.
It’s also often the case for @Before/After[All/Each]
methods (and the corresponding ones in older junit versions).
I don’t know if it holds true for other testing frameworks like TestNG.