Skip to content

Find test classes without tests - #1205

Merged
Jammy-Louie merged 7 commits into
mainfrom
add-rspec-s2187-test-classes-without-tests
Oct 26, 2026
Merged

Jammy-Louie merged 7 commits into
mainfrom
add-rspec-s2187-test-classes-without-tests

Conversation

@Jammy-Louie

@Jammy-Louie Jammy-Louie commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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 FindTestClassesWithoutTests search recipe marks classes in test sources that are named *Test, *Tests or *TestCase, or extend JUnit 3 TestCase, 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 @Nested classes. 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 ScanningRecipe because 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.

@Jammy-Louie
Jammy-Louie force-pushed the add-rspec-s2187-test-classes-without-tests branch from d0ca62a to 61e548b Compare October 23, 2026 14:55
@Jammy-Louie
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.
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Oct 26, 2026
@Jammy-Louie
Jammy-Louie merged commit 4e9335b into main Oct 26, 2026
1 check passed
@Jammy-Louie
Jammy-Louie deleted the add-rspec-s2187-test-classes-without-tests branch October 26, 2026 15:45
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants