Repository navigation
Find test classes without tests - #1205
Merged
Merged
Conversation
Jammy-Louie
force-pushed
the
add-rspec-s2187-test-classes-without-tests
branch
from
October 23, 2026 14:55
d0ca62a to
61e548b
Compare
Jammy-Louie
marked this pull request as ready for review
October 23, 2026 15:11
Resolved Zohhak, Pact and Karate test classes were marked as having no tests. Zohhak runs `@TestWith` methods, and the JUnit 4 `PactRunner` and `Karate` runners build their tests from pact and feature files, so a class using them needs no test methods of its own.
…classes-without-tests # Conflicts: # src/main/resources/META-INF/rewrite/recipes.csv
The recipe only looked at Java sources. It now also checks Kotlin and Groovy, through `JavaFileChecker`, `KotlinFileChecker`, `GroovyFileChecker` and `IsLikelyTest` preconditions rather than `isAcceptable` overrides. Kotlin leaves out the supertype of a class that only implements interfaces, so a missing supertype now only means "unresolved" for types not declared in the sources; unresolved `extends` clauses are recorded while scanning instead. Kotest, Spek and Spock specifications, which declare their tests in a DSL, and Kotlin `sealed` classes are not marked.
steve-aom-elliott
approved these changes
Oct 26, 2026
…classes-without-tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sonar rule S2187 reports test classes that contain no tests, as they suggest code is covered when it is not, and no recipe covered it yet. The new
FindTestClassesWithoutTestssearch recipe marks classes in test sources that are named*Test,*Testsor*TestCase, or extend JUnit 3TestCase, but contain no tests. It only searches, as adding tests or deleting the class needs a human.Java, Kotlin and Groovy classes are checked. Tests from JUnit 3, 4 and 5, TestNG, ArchUnit and Zohhak count, including inherited ones and those in
@Nestedclasses. Abstract and sealed classes and suites are not marked, nor are classes run by the Cucumber, Pact or Karate JUnit 4 runners, which build their tests from feature and pact files, or Kotest, Spek and Spock specifications, which declare their tests in a DSL.It is a
ScanningRecipebecause types do not list member classes and drop unresolved annotations, interfaces and superclasses. A class whose tests may be behind such a type is skipped rather than reported.Not covered: other JUnit 4 runners that build their tests from files.