You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use @DataJpaTest annotation on JUnit 5 test class. But I have few test classes with the same configuration. I added an interface to extract common methods and configuration. But there's a problem with @DataJpaTest annotation. If it's on the test class then everything is good. But if I put it on to the interface which test class extending then it's not working. It seems to be good to extend using annotation @DataJpaTest to interfaces.
@DataJpaTest // It worksclassMyTestClass {
}
interfaceMyCommonTestInterface1 { ... } // it works too
@DataJpaTest
interfaceMyCommonTestInterface2 { ... } // Don't work but I wanna remove duplication
classMyTestClass21: MyCommonTestInterface2 {}
classMyTestClass22: MyCommonTestInterface2 {}
The real case is if you're using Testcontainers and wanna start container ones for all tests (to save time), you need to create static container in the base class. I could be using abstract class for such case but I have not 1 container but N (cont_1, ..., cont_n), for example Postgres, Elastic, MyOther Service and I wanna start cont_1, cont_2 for 10 tests and start cont_5, cont_6 for another 20 tests and... Because I use interfaces like Scala traits to add them independently.
The text was updated successfully, but these errors were encountered:
This is happening due to Spring Framework's processing of imports. Spring Boot (through ImportsContextCustomizerFactory and ImportsContextCustomizer.ImportsSelector), registers the test class as a selected import from where its @Import annotations are processing by Framework. Framework does not consider imports on implemented interfaces so the @DataJpaTest-related imports are ignored.
I think the first step here is to explore the possibility of changing Framework's behavior. Things are a little inconsistent at the moment as, for example, the test context framework will find annotations on implemented interfaces.
The Framework team are happy to expand @Import processing to consider implemented interfaces. This will be a 7.0.x (at the earliest) feature so support for using a @…Test annotation on an implemented interface will land in Boot 4.0 at the earliest. I'm going to close this one as there's nothing to do in the Boot side other than a Framework upgrade once the new feature's available.
I use
@DataJpaTest
annotation on JUnit 5 test class. But I have few test classes with the same configuration. I added an interface to extract common methods and configuration. But there's a problem with@DataJpaTest
annotation. If it's on the test class then everything is good. But if I put it on to the interface which test class extending then it's not working. It seems to be good to extend using annotation@DataJpaTest
to interfaces.The real case is if you're using Testcontainers and wanna start container ones for all tests (to save time), you need to create static container in the base class. I could be using abstract class for such case but I have not 1 container but N (cont_1, ..., cont_n), for example Postgres, Elastic, MyOther Service and I wanna start cont_1, cont_2 for 10 tests and start cont_5, cont_6 for another 20 tests and... Because I use interfaces like Scala traits to add them independently.
The text was updated successfully, but these errors were encountered: