FP S2187 expecting TestNG annotated classes to have public test methods

Description

Rule S2187 states that test classes should not be empty. NoTestInTestClassCheck is implemented to have different behaviors when dealing with TestNg library. If the class is annotated with @org.testng.annotations.Test the check expects to find at least one test method that is also public, instead if the same annotation is not on the class, but only on the methods inside, they can all be private without any issue.
TestNg does not require any test method to be public, so the check should behave accordingly and should not raise if the test method is not public.

Non-compliant example:

@org.testng.annotations.Test(groups = "unitTests") class CommunityTest{ // Noncompliant {Add some tests to this class.} @Test void fun() { } }

In this example, just by removing the class annotation, the issue is resolved.

Activity

Michael GumowskiFebruary 28, 2023 at 12:57 PM

Done
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Labels

Start date

Components

Fix versions

Priority

Sentry

Created February 28, 2023 at 12:57 PM
Updated December 16, 2024 at 2:47 PM
Resolved December 12, 2024 at 10:41 AM