Skip to content

@DataJpaTest don't work on interface #3848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ars-java opened this issue Apr 20, 2025 · 1 comment
Closed

@DataJpaTest don't work on interface #3848

ars-java opened this issue Apr 20, 2025 · 1 comment
Labels
for: external-project For an external project and not something we can fix

Comments

@ars-java
Copy link

ars-java commented Apr 20, 2025

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 20, 2025
@mp911de mp911de added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 22, 2025
@mp911de
Copy link
Member

mp911de commented Apr 22, 2025

@DataJpaTest is a Spring Boot annotation. I'm not sure where details get lost. In any case, please report the issue against the Spring Boot issue tracker.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants