spring-projects / spring-modulith

Modular applications with Spring Boot
https://spring.io/projects/spring-modulith
Apache License 2.0
807 stars 138 forks source link

Parameters present in `@SpringBootTest` missing in `@ApplicationModuleTest` #890

Open aahlenst opened 2 weeks ago

aahlenst commented 2 weeks ago

@SpringBootTest (as of Spring Boot 3.4.0 M3) defines additional parameters not present in @ApplicationModuleTest: properties, useMainMethod, and args. I especially miss properties. For example, I use it to tell Flyway that it is okay to clean my database as part of the test lifecycle (spring.flyway.clean-disabled=true). While there are alternative methods to inject additional properties into the environment, for example, @DynamicPropertySource, the advantage of @SpringBootTest is its ease of use and that it is in a place where the properties are easy to find.

As an aside, I think it woul be great if @SpringBootTest and @ApplicationModuleTest could be separated or a separate annotation would be introduced that I could slap onto a normal @SpringBootTest or any other slice test. That would provide me the missing parameters of @SpringBootTest and allow me to use Modulith's testing facilities in any slice test (like @JooqTest).

odrotbohm commented 2 weeks ago

That's definitely an area of improvement we have on our radar. The latter is currently not possible due to the way that Boot implements the slice annotations. We're planning to improve that for 1.4 (May '25).

For the former, have you tried adding @SpringBootTest on your test class and applying the customizations in that re-declaration? The way the composed annotation mechanism works, the locally declared attribute values should trump the meta-annotated defaults.

aahlenst commented 2 weeks ago

For the former, have you tried adding @SpringBootTest on your test class and applying the customizations in that re-declaration? The way the composed annotation mechanism works, the locally declared attribute values should trump the meta-annotated defaults.

They do, indeed. Thanks for the hint.