Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alek/parameterized test #353

Merged
merged 19 commits into from
Jun 16, 2023
Merged

Alek/parameterized test #353

merged 19 commits into from
Jun 16, 2023

Conversation

AlekSimpson
Copy link
Contributor

@AlekSimpson AlekSimpson commented Jun 12, 2023

What's changed?

Adds a recipe to update @Test to @ParameterizedTest under certain conditions

What's your motivation?

Closes #314

Anything in particular you'd like reviewers to focus on?

The import statement for @ParameterizedTest is not being added when I run the tests. I've included the classpath and used all the necessary import methods.

Anyone you would like to review specifically?

@timtebeek

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ auto-formatter on affected files
  • I've updated the documentation (if applicable)

@AlekSimpson AlekSimpson self-assigned this Jun 12, 2023
@AlekSimpson AlekSimpson marked this pull request as draft June 12, 2023 23:07
@timtebeek timtebeek added the recipe Recipe request label Jun 13, 2023
Copy link
Contributor

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlekSimpson I think the hints I provided should help you make progress. The problem is that the JUnit API is split across multiple artifacts and you need to add them all explicitly to the classpath.

@AlekSimpson
Copy link
Contributor Author

AlekSimpson commented Jun 13, 2023

I updated the code with your suggested changes. Two tests are still failing, one fails because there is one extra space added at the start of the lines with the annotations and the method declaration. I'm not sure why that extra space is being included. My only guess is it has something to do with the .addAnnotation() coordinate line because that is the coordinate that test would be using.

The other test fails because when I try and reorder the annotations so that the @ParameterizedTest is on top it correctly does that but when it gets converted back into the code the annotations are on the same line (ex: @ParameterizedTest@SourceValue(..)).

@AlekSimpson
Copy link
Contributor Author

With the newest changes I made today all the tests are passing. I'm not sure why the checks on the ci build are still failing.

@timtebeek
Copy link
Contributor

With the newest changes I made today all the tests are passing. I'm not sure why the checks on the ci build are still failing.

You were missing the license headers; I've gone ahead and fixed that in c5c11bb ; it's also part of the checklist above.

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick suggestions for improvement

@AlekSimpson AlekSimpson marked this pull request as ready for review June 15, 2023 14:50
And removing @test with RemoveAnnotationVisitor
@timtebeek
Copy link
Contributor

Thanks a lot for this effort! I've added a polish commit to simplify things a bit:

  • remove @Test through RemoveAnnotationVisitor, to better reuse edge case handling already present there
  • always add @Parameterized at the start, removing the need for coordinates.replace() and reorderAnnotations
  • removes the call to maybeAutoFormat which is no longer needed now
  • reapplied a formatter to the source code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Remove duplicates uses of @TestTemplate implementations for a single method
3 participants