TestNG: SonarCloud fails to recognize test methods if the are not marked public

  • Languages of the repository
    JAVA

  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
    SonarCloud complains about TestCases not having a test, even though there are testNG-Test annotated methods if those are not marked public, which is technically not necessary

image

Hi,

Welcome to the community!

Is this Java?

 
Ann

Hi. Yes it is Java with TestNG. The Test Annotation is enough for TestNG to find test methods, whereas SonarCloud suggests to add Tests. This behavior changes, if the Test Annotated methods have the public modifier, even though for TestNG this is not necessary.

Thanks! I’ve flagged this for the relevant folks.

 
Ann

1 Like

Hi Uwe, thank you for reporting, indeed the check implementing rule S2187, is mistakenly expecting the public modifier on the test method you provided, also, it seems like if you for example remove the @Test(groups = "unitTests") annotation from the class, the check will not report any issue because is still supporting the TestNG library annotations for the methods inside a test class. :man_shrugging:
I have created a ticket to fix this, and we will work on it as soon as we can,
Leonardo