Skip to content

Migrate Spring Batch Integration to JUnit Jupiter #4124

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

Merged
merged 1 commit into from
Aug 2, 2022
Merged

Migrate Spring Batch Integration to JUnit Jupiter #4124

merged 1 commit into from
Aug 2, 2022

Conversation

hpoettker
Copy link
Contributor

As of now, most of Spring Batch's tests are written with JUnit 4 which works mostly fine but lacks some niceties (e.g. parameterized tests are a bit cumbersome), and can lead to issues when integrating with test frameworks of other projects. 😉

This PR migrates the tests of Spring Batch Integration fully to JUnit 5 such that JUnit 4 is no longer on the classpath of the module.

The changes are optimized for reviewability in the sense that I tried to keep them minimal. E.g. all the public modifiers are still there as their removal would be very noisy.

The most part of the PR has been done by automation. Only AsyncItemProcessorMessagingGatewayTests and PollingAsyncItemProcessorMessagingGatewayTests were migrated manually for the most part.

Please let me know if you're interested in the same for the other modules.

@fmbenhassine
Copy link
Contributor

This is awesome! Thank you for contributing this update, REALLY appreciated 👍

The changes are optimized for reviewability in the sense that I tried to keep them minimal. E.g. all the public modifiers are still there as their removal would be very noisy.

That noise is not issue for the review. If we decide to move to JUnit 5, let's do it in a clean way from the beginning. Please go ahead and apply all the best practices recommended by JUnit 5 in this PR (and others).

The most part of the PR has been done by automation.

Nice! Just curious, which automation tool have you used? We had an internal discussion about this kind of migrations and we were planning to use open-rewrite for it. We had a successful PoC by the team at moderne.io in #3945.

Please let me know if you're interested in the same for the other modules.

Yes please! a PR per module should work.

Please note that we are planning to review testing support in Spring Batch in 5.0.0-M5, so those PRs would be reviewed only when we start working on that milestone. Many thanks upfront.

@hpoettker
Copy link
Contributor Author

Thanks for the detailed and encouraging feedback! I'm also quite intrigued by the promises of OpenRewrite and Spring Boot Migrator. This PR is basically a by-product of me having a look at them.

To explore the problem space and to create a baseline for a fair comparison, I approached the problem with sed commands, quick-and-dirty scripting, and manual finishing touches. That's what I euphemistically referred to as "automation". 😄

I set out with the expectation to give up at some point but got surprisingly far as the programming style is very consistent for a code base of this size and age. The only pain was the migration from expected exceptions at the @Test level to assertThrows around the specific throwing line. I didn't want to wrap the whole body of the functions and the heuristic that it's most likely the last line didn't really work out. But that's a problem that I don't expect automated tools to solve based on static code analysis.

I'll try out the fully automated solutions in the next days. It would be fun to discuss this kind of PR on the level of recipes to be selected. I'll keep you posted.

@hpoettker
Copy link
Contributor Author

I've replaced the explicit catches of expected exceptions with assertThrows. Furthermore, I've removed unnecessary public modifiers and throws clauses, used static imports for assertions, and replaced the remaining explicit catching of expected exceptions.

I think the PR now has a nice scope for a JUnit 5 migration. Please let me know whether you agree or if you'd increase or decrease the scope.

Something that could be considered is a migration to AssertJ. But I think this PR would get unmanageable, if it were included here.

@hpoettker
Copy link
Contributor Author

As 5.0.0-M4 has been released, I've squashed and rebased the latest state on the commit with the tag 5.0.0-M4.

@fmbenhassine fmbenhassine mentioned this pull request Jul 27, 2022
5 tasks
@fmbenhassine fmbenhassine merged commit ae5ffd2 into spring-projects:main Aug 2, 2022
@hpoettker hpoettker deleted the jupiter-integration branch August 17, 2022 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants