spring-modulith
spring-modulith copied to clipboard
ApplicationModuleTest in Nested JUnit Test fails
trafficstars
Hello,
i recognized a weired behaviour when executing JUnit tests using @ApplicationModuleTest. The following example is a simplified demo to reproduce the error. In this example i am using version 1.2.1 of the modulith project.
If i execute the tests the innner test within the nested class fails. If i uncomment the test case in the outer class both tests are successful. The demo is a simple project with just one module (link to the demo project at the end of the issue).
@ApplicationModuleTest
@Import(TestcontainersConfiguration.class)
public class AbstractCustomerTest {
}
@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = {"classpath:sql/customer.sql"})
class CustomerServiceTest extends AbstractCustomerTest {
@Autowired
private CustomerService service;
// @Test
// void getCustomer() {
// assertThat(service.get(1L))
// .isNotNull()
// .satisfies(c -> {
// assertThat(c.id()).isNotNull();
// assertThat(c.name()).isEqualTo("John Doe");
// });
// }
@Nested
class Slice {
@Test
void getCustomer() {
assertThat(service.get(1L))
.isNotNull()
.satisfies(c -> {
assertThat(c.id()).isNotNull();
assertThat(c.name()).isEqualTo("John Doe");
});
}
}
}
A complete sample application can be found here: https://github.com/chhorz/modulith-test-demo