Repository navigation
Conversation
Add `AddMissingTestAnnotation`, which finds methods in an existing test class that look like forgotten tests: void, non-private, non-static, no parameters, a name starting with `test`, and a body containing at least one assertion (JUnit 4/5, AssertJ, Hamcrest, Mockito verify). By default the recipe only flags such methods with a search result. Setting `addAnnotation` to `true` adds `@Test`, matching the framework the class already uses (JUnit 4 or JUnit 5). Classes that mix both frameworks, or have no `@Test` method at all, are left untouched. Fixes openrewrite#772
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.
@Testannotations #772What's changed?
Adds
AddMissingTestAnnotation, which finds forgotten tests: methods in an existing test class that arevoid, non-private, non-static, take no parameters, have a name starting withtest, and contain at least one assertion (JUnit 4/5, AssertJ, Hamcrest, Mockitoverify).addAnnotation=trueadds@Test, matching the framework the class already uses (JUnit 4 or 5).@Testmethods, or with no@Testmethod, are left untouched.What's your motivation?
Tests that lose their
@Testannotation silently stop running. Following the discussion in #772, @timtebeek was hesitant about annotating automatically (for example a deliberately disabled database test), so the default only flags.Anything in particular you'd like reviewers to focus on?
testname prefix and an assertion. This avoids turning helpers liketestDataSetup()into tests, but misses real tests without the prefix, or ones asserting through custom helpers.Have you considered any alternatives or workarounds?
"Name OR assertion" catches more tests, but it would annotate helpers, which
RemoveTestPrefixcould then rename.Any additional context
AddMissingTestAnnotationTest: positive and negative cases, JUnit 4 and 5, mixed classes, AssertJ/Hamcrest/Mockito, lifecycle annotations, the default (null) option, abstract methods and nested classes.recipes.csvcontains only the new entry. I ran the test class andrecipeCsvGeneratelocally, but not a full./gradlew build, so I'm relying on CI for that. My local dependency setup changed other rows' counts when regenerating, so I did not commit those.test...that asserts would still be annotated in opt-in mode.cleanupthe right package, and should the recipe be added to a composite recipe (for example incleanup.yml)? I left that out for now.Checklist
./gradlew buildlocally, and committed any resulting changes torecipes.csv