False positive on Nested JUnit 5 classes on S3577

Rule S3577 checks a name of the test to comply with naming rules. It checks for a name, if a class contains a test method. JUnit 5 introduced nested classes that should be excluded from this rule as they do not need to be searched by surefire or failsafe or other tests executors.

Example of false positive:

class JunitNestedTest {
  @org.junit.jupiter.api.Nested
  class Positive {
    @org.junit.jupiter.api.Test
    void foo() {}
  }
}

class JunitNested { // Noncompliant
  @org.junit.jupiter.api.Nested
  class Negative {
    @org.junit.jupiter.api.Test
    void foo() {}
  }
}

This will report on Positive class, but shouldn’t. I will not report on JunitNested class, but it should.

I’ve started to work on a bug fix. You can see a WIP here: https://github.com/SonarSource/sonar-java/compare/master...wavesoftware:bugfix/s3577-junit5-nested

Affected version: sonar-java @ master

Cheers!

PR has been filed: https://github.com/SonarSource/sonar-java/pull/2667

Cheers!

Hey,

Sorry for the late reply. I’ll handle your PR as soon as possible. In the meantime, I created the corresponding ticket to track it: SONARJAVA-3193.

Cheers,
Michael