Skip to content

Conversation

@amishra-u
Copy link
Contributor

Implement a scanning recipe that identifies and marks JUnit 4 test classes eligible for migration to JUnit 5. This precondition recipe analyzes test classes to determine migratability based on:

  • Detection of supported vs. unsupported JUnit 4 rules and runners
  • Analysis of class inheritance hierarchies to ensure parent and child test classes use only supported features
  • Identification of @parameters annotations with class-type source attributes that cannot be migrated
  • Validation that all ancestors in the class hierarchy are also migratable

The recipe marks only those test classes that can be successfully migrated, preventing build or test failures post-migration. This ensures fully automated, safe migrations by excluding classes with unsupported features from the migration process.

This precondition recipe is designed to work with declarative JUnit 4 to JUnit 5 migration recipes, ensuring the migration recipe only modifies classes that are guaranteed to migrate successfully.

Note: This recipe has been successfully used at Uber for large-scale JUnit 4 to JUnit 5 migrations. Upstreaming to benefit the broader OpenRewrite community.

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

🤖 Generated with Claude Code

Implement a scanning recipe that identifies and marks JUnit 4 test classes eligible for migration to JUnit 5. This precondition recipe analyzes test classes to determine migratability based on:

- Detection of supported vs. unsupported JUnit 4 rules and runners
- Analysis of class inheritance hierarchies to ensure parent and child test classes use only supported features
- Identification of @parameters annotations with class-type source attributes that cannot be migrated
- Validation that all ancestors in the class hierarchy are also migratable

The recipe marks only those test classes that can be successfully migrated, preventing build or test failures post-migration. This ensures fully automated, safe migrations by excluding classes with unsupported features from the migration process.

This precondition recipe is designed to work with declarative JUnit 4 to JUnit 5 migration recipes, ensuring the migration recipe only modifies classes that are guaranteed to migrate successfully.

Note: This recipe has been successfully used at Uber for large-scale JUnit 4 to JUnit 5 migrations. Upstreaming to benefit the broader OpenRewrite community.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@timtebeek timtebeek added recipe Recipe request junit labels Dec 22, 2025
@timtebeek timtebeek self-requested a review December 22, 2025 09:18
Copy link
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 for showcasing what you've done here @amishra-u ; Good to see how you're using this scanning precondition to limit results just to the whitelisted cases you know you can handle. Could be helpful for others looking to gradually adopt JUnit Jupiter still, with known cases not yet converted.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

junit recipe Recipe request

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

2 participants