Skip to content

@ApplicationModuleTest not inheriting the @Import classes from Base Test #1583

@sivaprasadreddy

Description

@sivaprasadreddy

Until Spring Modulith 2.0.0 the following test setup is working fine.

@Import(TestcontainersConfiguration.class)
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {
    @Autowired
    protected MockMvcTester mockMvcTester;
}


@ApplicationModuleTest(
        webEnvironment = RANDOM_PORT,
        mode = DIRECT_DEPENDENCIES,
        extraIncludes = {"config", "users"})
class AdminBooksControllerTests extends AbstractIntegrationTest {
    //tests
}

But when I upgrade to Spring Modulith 2.0.1 or 2.0.2, the TestcontainersConfiguration is not considered and failed with the following error:

WARN  org.springframework.boot.web.server.servlet.context.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.sivalabs.bookstore.common.TestcontainersConfiguration' available

I can work around this by simply adding @Import(TestcontainersConfiguration.class) to all the tests like AdminBooksControllerTests. But instead of duplicating the configuration, I would prefer to have it in parent base test and work as it used to in Spring Modulith 2.0.0.

PS: Reproducer repo https://github.com/sivaprasadreddy/bookstore

More context:
The TestcontainersConfiguration and AbstractIntegrationTest are in common package com.sivalabs.bookstore.common and AdminBooksControllerTests is in com.sivalabs.bookstore.admin.web package then it is failing. However, if I move TestcontainersConfiguration and AbstractIntegrationTest to the base package com.sivalabs.bookstore then its working fine.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions