Rule is java:S2187 - TestCases should contain tests (SonarQube v9.9)
We have number of places where a superclass contains a set of tests and then one or more sub-classes provide different configurations or inputs for those tests but no additional tests. Something like the following …
public class ReferencesResolverSLDTest extends ReferencesResolverTest
public void setUp() throws Exception
switchLegacyMode(false); // superclass has legacy mode set to true
The java:S2187 rule complains that the subclass has no test methods but it does because it inherits and reuses the tests from it superclass. This gives us loads of false positives. Could the rule be modified to check if the class inherits tests from a superclass?
Hi Stephen, thank you for the report. Sadly right now the analyzer does not keep track of methods in other files for this rule. That means that it has no clue that the parent class has methods with some
It is most likely something that we would want to make better, but I’m not sure on the priority for this.
I created a ticket for this specific issue, if you want to keep track on the progress.
Meanwhile, one workaround that I can suggest, if it does not have a huge impact on your project, is to move child and parent classes in the same file.
Thanks for info. Unfortunately, it’s not likely we can make such significant changes to that part of our code base. We will deactivate that rule in our quality profiles for now.