-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
I use @DataJpaTest annotation on JUnit5 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 works
class MyTestClass {
}
// ----------
interface MyCommonTestInterface1 { ... } // it works too
@DataJpaTest
class MyTestClass11: MyCommonTestInterface1 {}
@DataJpaTest
class MyTestClass12: MyCommonTestInterface1 {}
// ----------
@DataJpaTest
interface MyCommonTestInterface2 { ... } // Don't work but I wanna remove duplication
class MyTestClass21: MyCommonTestInterface2 {}
class MyTestClass22: 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.