apache / bookkeeper

Apache BookKeeper - a scalable, fault tolerant and low latency storage service optimized for append-only workloads
https://bookkeeper.apache.org/
Apache License 2.0
1.88k stars 893 forks source link

Migrate tests from junit4 to junit5 #4322

Open shoothzj opened 2 months ago

shoothzj commented 2 months ago

JUnit 5 offers significant improvements over JUnit 4, including more powerful and flexible testing capabilities like annotation-based coding(so we don't need to write assume), parallel test execution, and other features. We can write new test classes using junit5, and existing-test classes can be slowly migrated.

This issue to track tests migrate to junit5, we can migrate a package、a small module gradually.

See also: https://lists.apache.org/thread/hlyc722gy45s3y61q7n79hdcr6cgrx7v

sherlock-lin commented 2 months ago

@shoothzj Hi shoothzj, I'm very interested in this job, can I have it processed?

shoothzj commented 2 months ago

@sherlock-lin Sure, go ahead, I think we'd better change less than 15 files in one Pull Reuqest.

sherlock-lin commented 2 months ago

@sherlock-lin Sure, go ahead, I think we'd better change less than 15 files in one Pull Reuqest.

Okay, I'll do it in small batches.

lhotari commented 1 month ago

OpenRewrite contains support for Junit4 to Junit5 migration. It's probably worth using it to assist in the migration. https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-from-junit-4-to-junit-5

I'd also recommend using AssertJ for more complex assertions since the error messages that AssertJ creates are much better than ordinary asserts.

there's also a recipe for migrating to use AssertJ: https://docs.openrewrite.org/running-recipes/popular-recipe-guides/junit-asserts-to-assertj

lhotari commented 1 month ago

It looks like IntelliJ Ultimate has Junit 4 -> Junit 5 refactoring in the IDE:

image

It doesn't seem very useful since it's not migrating the assertions. That's why OpenRewrite is more practical. There seems to be OpenRewrite recipe support in IntelliJ too.

sherlock-lin commented 1 month ago

OpenRewrite contains support for Junit4 to Junit5 migration. It's probably worth using it to assist in the migration. https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-from-junit-4-to-junit-5

I'd also recommend using AssertJ for more complex assertions since the error messages that AssertJ creates are much better than ordinary asserts.

there's also a recipe for migrating to use AssertJ: https://docs.openrewrite.org/running-recipes/popular-recipe-guides/junit-asserts-to-assertj

Thanks, I needed this so much. : )