Reducing the visibility public JUnit 5 test classes and test methods when SonarLint is installed
The documentation on https://blog.jetbrains.com/idea/2020/09/writing-tests-with-junit-5/ states:
One thing to note for JUnit 5 tests is that the test method doesn’t need to be public in order to work. IntelliJ IDEA will let you know if the class or method can have reduced visibility and still work. Use Alt+Enter to have the IDE remove
public
from the class declaration, and re-run the test to make sure it works as expected.
My IntelliJ installation (with Sonarlint installed) reports these as SonarLint issued called "Remove this 'public' modifier" when I analyze the code. When I then selected "Show Quick Fixes" IntelliJ does not offer me to reduce the visibility of these methods, but only offers to show the Sonar rule description:
Does Sonar override the default IntelliJ behaviour or am I doing something wrong?
If this happens because of Sonar, is there still a way to access the default IntelliJ quick fix?
Please sign in to leave a comment.
Yes, SonarLint has its own inspections & quick fixes. The ones on your screenshot seem to belong to SonarLint, that's why there are no IDE suggestions for them.
Relevant IDE inspections would look like this:
And would have the following quick fix:
Hello Arina Efremova,
thanks for your answer.
Is there any way to still acces the Idea quick fixes when a plugin like SonarLint has overriden them? I am not allowed to disable sonar due to corporate policy.