Skip to content

GH-3840: Migrate Redis tests to Testcontainers #3847

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

Closed
wants to merge 3 commits into from

Conversation

oxcafedead
Copy link
Contributor

Fixes #3840

  • Create a new abstraction RedisTest for Testcontainers-based tests
  • Move existing common utility methods to the new interface
  • Migrate all existing Redis tests to use this new RedisTest interface
  • Migrate all existing Redis tests to JUnit5
  • Make all existing Redis tests confirming to JUnit5 standards, such as
    default methods and classes visibility instead of public
  • Add a dependency for parametrized tests in JUnit5
  • Improve assertions readability across tests, for instance:
    assertThat(thing.size()).isEqualTo(2) -> assertThat(thing).hasSize(2)
  • Add real assertions to
    RedisLockRegistryTests.twoRedisLockRegistryTest (earlier it did not
    have assertions at all)
  • Reformat, rearrange and cleanup the code

Fixes spring-projects#3840

* Create a new abstraction `RedisTest` for Testcontainers-based tests
* Move existing common utility methods to the new interface
* Migrate all existing Redis tests to use this new `RedisTest` interface
* Migrate all existing Redis tests to JUnit5
* Make all existing Redis tests confirming to JUnit5 standards, such as
default methods and classes visibility instead of public
* Add a dependency for parametrized tests in JUnit5
* Improve assertions readability across tests, for instance:
assertThat(thing.size()).isEqualTo(2) -> assertThat(thing).hasSize(2)
* Add real assertions to
`RedisLockRegistryTests.twoRedisLockRegistryTest` (earlier it did not
have assertions at all)
* Reformat, rearrange and cleanup the code
@oxcafedead
Copy link
Contributor Author

Sorry for many changes to review, but I decided that is would be better that 'chunk-based' approach.
Just for the note, locally I've run :spring-integration-redis:testAll and :spring-integration-file:testAll to verify the migration.

@oxcafedead
Copy link
Contributor Author

oxcafedead commented Jul 14, 2022

I also noticed that no JUnit5 tests follow the recommendation from JUnit to use default classes/methods visibility:
https://junit.org/junit5/docs/current/user-guide/#writing-tests-classes-and-methods

It is generally recommended to omit the public modifier for test classes, test methods, and lifecycle methods unless there is a technical reason for doing so – for example, when a test class is extended by a test class in another package. Another technical reason for making classes and methods public is to simplify testing on the module path when using the Java Module System.

I removed public for redis tests by inertia, however if this is some sort of convention for the project I can revert this change.

UPD
Actually some tests do follow default visibility (at least for methods), so probably is is OK. Ignore this comment 😄

@artembilan
Copy link
Member

Hi @oxcafedead !

Thank you for your thorough contribution as usual!

Re. public on test method.
Previously all our tests were on JUnit 4, where public is required.
We migrate to JUnit 5 gradually, when we touch the test.

It is really some burden to remove all those public in the class and does not look like leaving it cause some harm.

And from the JUnit doc you've mentioned:

Test classes, test methods, and lifecycle methods are not required to be public, but they must not be private.

So, doesn't look like there is a strong requirement to do that extra work removing the public modifier.

Therefore there is no any convention from our side how to be with such a migration.
First of all it is just about tests, so the code might not be ideal.
Secondly, it is better to be reasonable what you do, but don't waste your time for something what is not painful like this public modifier removal.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Just a couple nit-picks.

Otherwise this is great work, @oxcafedead , as usual!

Fix a couple of small changes after the code review:
* Change base interface name to be consistent with other similar places
* Typo in javadocs
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

LGTM.

Pulling locally for final verification and merging...

Small tests readability improvement regarding assertions
@artembilan
Copy link
Member

Merged as 1c461a3 after some minor compatibility fix.

@oxcafedead ,

thank you again.

@artembilan artembilan closed this Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Redis integration tests to Testcontainers
2 participants