Skip to content

@ApplicationModuleTest in separate test files does not cache the ApplicationContext #1050

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
stephen-j-arnold opened this issue Feb 4, 2025 · 2 comments
Assignees
Labels
in: test support Spring Boot integration testing type: bug Something isn't working
Milestone

Comments

@stephen-j-arnold
Copy link

Somewhat related to #725

When creating @ApplicationModuleTest's across test files within the same module, the ApplicationContext is not cached. From what I can see, ModuleContextCustomizerFactory.hashCode() is considering the source Class (which is the Test class) and that results in separate tests to be considered 'different' from a AC cache perspective. Though, from an actual AC perspective, these are the same contexts.

Relatively easy to re-produce in the spring-modulith-example-full module. I just added a duplicate OrderIntegrationTest called AnotherOrderIntegrationTest in a separate test file, and when running these together, I'd expect to have 1 AC but am seeing 2. Along with 2 cache misses logging.level.org.springframework.test.context.cache=debug, where I'd expect 1 (loading it for the first test (miss) but not the second (hit)).

@odrotbohm
Copy link
Member

This has been tweaked to rather resort to the underlying execution than the individual test class. Feel free to give the 1.4 or 1.3.3 snapshots a try.

@odrotbohm odrotbohm added this to the 1.4 M2 milestone Feb 24, 2025
@stephen-j-arnold
Copy link
Author

Sorry - I'm just getting to pull in 1.3.4 now & can confirm this issue is still present. Seems to be coming from ModuleTypeExcludeFilter now. Can we make the same tweak to the equals and hashCode functions on that object? From what I can see, that does seem to resolve the issue fully. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test support Spring Boot integration testing type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants