Skip to content

Recipe to check that Kotlin test methods return Unit#871

Merged
timtebeek merged 14 commits intoopenrewrite:mainfrom
greg-dennis:main
Dec 11, 2025
Merged

Recipe to check that Kotlin test methods return Unit#871
timtebeek merged 14 commits intoopenrewrite:mainfrom
greg-dennis:main

Conversation

@greg-dennis
Copy link
Copy Markdown
Contributor

@greg-dennis greg-dennis commented Dec 11, 2025

What's changed?

Recipe to check that Kotlin test methods return Unit.

What's your motivation?

To catch and rewrite Kotlin test methods that do not return Unit and so would be skipped by the JUnit test runner.

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

Stylistic consistency.

Anyone you would like to review specifically?

@timtebeek

Have you considered any alternatives or workarounds?

No

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@greg-dennis greg-dennis marked this pull request as ready for review December 11, 2025 03:40
@timtebeek timtebeek self-requested a review December 11, 2025 08:15
@timtebeek timtebeek added enhancement New feature or request recipe Recipe request junit labels Dec 11, 2025
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Dec 11, 2025
Copy link
Copy Markdown
Member

@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.

Thanks a lot for the initiative and help here @greg-dennis ! Nice to have this addition as I imagine it's a subtle and quiet bug that nevertheless can have negative consequences.

After the merge you can already use our snapshot versions; we'll release probably next Tuesday.

@greg-dennis
Copy link
Copy Markdown
Contributor Author

Thanks for your help getting this done! So the type validation of MethodInvocation issue won't affect the recipe when run on production code; it only matters insofar as we're trying to run a unit test?

@timtebeek
Copy link
Copy Markdown
Member

Thanks for your help getting this done! So the type validation of MethodInvocation issue won't affect the recipe when run on production code; it only matters insofar as we're trying to run a unit test?

Yep; we have that as an additional check there as it might affect how recipes can be chained together. In this case I think it's fine to have that be imperfect, as we can still achieve the change you're after and likely won't see overlapping changes be affected.

Hope you're ok with me closing your other PRs that merely aimed to demonstrate the issue, or provide a workaround not using .typeValidationOptions(....

@timtebeek timtebeek merged commit f378cb5 into openrewrite:main Dec 11, 2025
2 checks passed
@greg-dennis
Copy link
Copy Markdown
Contributor Author

Hope you're ok with me closing your other PRs that merely aimed to demonstrate the issue, or provide a workaround not using .typeValidationOptions(....

Yup, feel free to close those PRs

@greg-at-moderne
Copy link
Copy Markdown
Contributor

Reported #874 which might be related to this PR.

mergify bot added a commit to robfrank/linklift that referenced this pull request Dec 22, 2025
…rom 3.23.0 to 3.24.0 [skip ci]

Bumps [org.openrewrite.recipe:rewrite-testing-frameworks](https://github.com/openrewrite/rewrite-testing-frameworks) from 3.23.0 to 3.24.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-testing-frameworks's releases](https://github.com/openrewrite/rewrite-testing-frameworks/releases).*

> 3.24.0
> ------
>
> What's Changed
> --------------
>
> * Recipe to check that Kotlin test methods return Unit by [`@​greg-dennis`](https://github.com/greg-dennis) in [openrewrite/rewrite-testing-frameworks#871](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/871)
> * Reorder `maybeRemoveImport` before `maybeAddImport` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#873](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/873)
> * Add test for Kotlin by [`@​Laurens-W`](https://github.com/Laurens-W) in [openrewrite/rewrite-testing-frameworks#876](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/876)
>
> New Contributors
> ----------------
>
> * [`@​greg-dennis`](https://github.com/greg-dennis) made their first contribution in [openrewrite/rewrite-testing-frameworks#871](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/871)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.23.0...v3.24.0>


Commits

* [`5459e88`](openrewrite/rewrite-testing-frameworks@5459e88) Add test for Kotlin ([#876](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/876))
* [`20cca13`](openrewrite/rewrite-testing-frameworks@20cca13) Only match methods with test annotations
* [`9803871`](openrewrite/rewrite-testing-frameworks@9803871) Reorder `maybeRemoveImport` before `maybeAddImport` ([#873](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/873))
* [`42c22af`](openrewrite/rewrite-testing-frameworks@42c22af) Add documentation example for `KotlinTestMethodsShouldReturnUnit`
* [`f378cb5`](openrewrite/rewrite-testing-frameworks@f378cb5) Recipe to check that Kotlin test methods return Unit ([#871](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/871))
* [`69f23b7`](openrewrite/rewrite-testing-frameworks@69f23b7) OpenRewrite recipe best practices
* [`76041b7`](openrewrite/rewrite-testing-frameworks@76041b7) Remove unused local variable
* [`edf6bcd`](openrewrite/rewrite-testing-frameworks@edf6bcd) Add test for Kotlin
* See full diff in [compare view](openrewrite/rewrite-testing-frameworks@v3.23.0...v3.24.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-testing-frameworks&package-manager=maven&previous-version=3.23.0&new-version=3.24.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request junit recipe Recipe request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants