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
When running tests written in Kotlin with the '@DataJpaTest' annotation, the application context is started for every class ran, rather then re-using the existing one on the cache.
Versions
Spring Boot - 1.4.1.RELEASE
Kotlin - 1.0.4
Java - 1.8
Details
I am running into an issue when using Kotlin to write my integration tests with @DataJpaTest. When I run all of the tests together, I expect the @DataJpaTest classes to re-use the first application context, however they all end up starting their own. When I tried writing the same basic test in Java, only one application context was started.
Using IntelliJ's Kotlin tools, I decompiled the Kotlin code into Java. Now, when I run the new Java tests, it behaves in the same way as Kotlin, which was expected. The difference I noticed is the Kotlin @Metadata annotation. When I comment out the values d1 and d2 in the annotation (or the whole annotation), the new Java tests work properly, only starting one application context.
Also, switching the Kotlin tests to use the @SpringBootTest worked with only one application context starting.
I tried making a post on Kotlin's discussion board, but failed to get a response. I'm hoping your team may be able to provide insight on how I can work around this issue in Kotlin. Or if it is something that can be resolved on your end.
I've included sample Kotlin code, sample Java code, as well as attached a sample project used to replicate my issue.
The MergedContextConfiguration class is the thing that acts as the cache key. My guess is that something in the class is using the class annotations in the equals method.
The root cause is ImportsContextCustomizer.ContextCustomizerKey which is collecting all class level annotations (including the implicit ones added by Kotlin)
Uh oh!
There was an error while loading. Please reload this page.
Issue
When running tests written in Kotlin with the '@DataJpaTest' annotation, the application context is started for every class ran, rather then re-using the existing one on the cache.
Versions
Spring Boot - 1.4.1.RELEASE
Kotlin - 1.0.4
Java - 1.8
Details
I am running into an issue when using Kotlin to write my integration tests with
@DataJpaTest
. When I run all of the tests together, I expect the@DataJpaTest
classes to re-use the first application context, however they all end up starting their own. When I tried writing the same basic test in Java, only one application context was started.Using IntelliJ's Kotlin tools, I decompiled the Kotlin code into Java. Now, when I run the new Java tests, it behaves in the same way as Kotlin, which was expected. The difference I noticed is the Kotlin
@Metadata
annotation. When I comment out the valuesd1
andd2
in the annotation (or the whole annotation), the new Java tests work properly, only starting one application context.Also, switching the Kotlin tests to use the
@SpringBootTest
worked with only one application context starting.I tried making a post on Kotlin's discussion board, but failed to get a response. I'm hoping your team may be able to provide insight on how I can work around this issue in Kotlin. Or if it is something that can be resolved on your end.
I've included sample Kotlin code, sample Java code, as well as attached a sample project used to replicate my issue.
Kotlin
Java (generated from Kotlin decompiler)
Sample Project
kotlin-and-datajpatest.zip
The text was updated successfully, but these errors were encountered: