Skip to content

[java] TestClassWithoutTestCases: False positive for test classes extending a class with tests (in nested classes) #5011

Closed

Description

@Wolf2323

Affects PMD Version: 7.1.0

Rule: TestClassWithoutTestCases

Description:
In PMD 6 this was no issue, now in PMD 7 a nested test class is now detected as TestClassWithoutTestCases. I guess previously the class was not detected as test class at all. Now it is detected, and yes it actually has no tests, but they are on the super class.

Code Sample demonstrating the issue:

public class SpeedProfilerTests extends TimeProfilerTests {
	@Nested
	class operations extends TimeProfilerTests.operations {
		@Override
		protected TimeProfiler makeProfiler() {
			return new SpeedProfiler("foo");
		}
	}

Expected outcome:
No violations, as the super class actually has test cases

[INFO] PMD Failure: works.reload.recore.util.operations:22 Rule:TestClassWithoutTestCases Priority:3 The class 'operations' might be a test class, but it contains no test cases..

Running PMD through: Maven

Activity

  1. added
    a:false-positive
    on May 13, 2024
  2. changed the title [-]TestClassWithoutTestCases - false-positive for test classes extending a class with tests (in nested classes)[/-] [+][java] TestClassWithoutTestCases - false-positive for test classes extending a class with tests (in nested classes)[/+] on May 13, 2024
  3. added 3 commits that reference this issue on Jun 23, 2026
    f189164
    1089f52
    884e3b6
  4. changed the title [-][java] TestClassWithoutTestCases - false-positive for test classes extending a class with tests (in nested classes)[/-] [+][java] TestClassWithoutTestCases: False positive for test classes extending a class with tests (in nested classes)[/+] on Jun 29, 2026
  5. modified the milestones: 7.27.0, 7.26.0 on Jun 29, 2026
  6. added a commit that references this issue on Jun 29, 2026
    9733420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions