spring-modulith icon indicating copy to clipboard operation
spring-modulith copied to clipboard

Allow using `@ApplicationModuleTest` outside of a module package

Open odrotbohm opened this issue 1 year ago • 1 comments

Discussed in https://github.com/spring-projects/spring-modulith/discussions/413

Originally posted by marinusgeuze December 11, 2023 Hi,

In our project, we have organized our tests into different root packages based on their types, such as unit tests, integration tests, and end-to-end tests. Consequently, our Spring Boot Integration Tests are placed in a package different from their corresponding modules, leading to the occurrence of the “Package %s is not part of any module!” error.

To provide more context, our test package structure looks something like this:

unit.com.test..*UnitTest
it.com.test..*IntegrationTest
end2end.com.test..*End2EndTest

We are seeking a solution to explicitly define the module to which a Spring Boot Integration Test belongs. This as part of the ApplicationModuleTest annotation. Or ideally, we would like to add the it.com.test package to the module. Is there a way to achieve this?

We acknowledge that a possible recommendation might be to group tests within the module boundaries, like com.test..unit.*UnitTest, com.test..it.*IntegrationTest, etc. However, this is not a feasible option for us due to the configuration constraints of our test frameworks.

odrotbohm avatar Jan 17 '24 23:01 odrotbohm

We could / would need to add the following attributes to @ApplicationModuleTest:

  • module (String) – the logical name of the module to bootstrap
  • classes (alias of @SpringBootTest(classes) – to explicitly point to the main application class

ModuleTestExecution would need to be altered to skip the module detection in case module is configured. Furthermore, we'd have to inspect the classes manually configured for a @SpringBootApplication annotation to detect the primary application class before falling back to the lookup via a package traversal.

odrotbohm avatar Jan 17 '24 23:01 odrotbohm

@odrotbohm can I draft a PR for this issue?

lukasdo avatar May 20 '24 18:05 lukasdo

This should now work. Thanks, @lukasdo, for providing the PR.

odrotbohm avatar Jul 18 '24 21:07 odrotbohm

Thanks @lukasdo for your work

marinusgeuze avatar Jul 19 '24 18:07 marinusgeuze