Ido Flax
06/15/2022, 1:35 PMLeoColman
06/15/2022, 10:42 PMthanksforallthefish
06/16/2022, 6:00 AMclass ProjectConfig : AbstractProjectConfig() {
override fun extensions() = listOf(
SpringExtension,
SpringAutowireConstructorExtension,
... more extensions
)
...
}
@AutoConfigureMockMvc
@SpringBootTest
@Transactional
class MyIntegrationTest(
private val mockMvc: MockMvc,
private val testMother: TestMother,
private val messageOutboxRepository: MessageOutboxRepository,
) : StringSpec()
each test is then rollbacked (because @Transactional
annotation)Ido Flax
06/16/2022, 6:14 AM@DataJpaTest
@ImportAutoConfiguration(RefreshAutoConfiguration::class)
@ContextConfiguration(
classes = [HiveConfig::class, TableIsDBConfig::class],
initializers = [DataAccessTestInitializer::class]
)
@ActiveProfiles("integration-test, qa")
@ComponentScan(basePackages = ["com.bla"])
abstract class DataAccessTest : FeatureSpec() {
//spring extension here (i already removed kotest from my pom)
}
thanksforallthefish
06/16/2022, 6:18 AM@Transactional
annotation in there, then it should work.
I don’t use test slices, but I think @DataJpaTest
configures everything related to persistence, so transaction should definitely work
(I don’t use test slices because coincidentally I think they make your test suite slower, since the application context is memoized if all tests share the same context it is initializated only once, if you start using test slices you get multiple contexts, data, web, jackson, etc etc)Ido Flax
06/16/2022, 6:39 AMIdo Flax
06/16/2022, 6:53 AMIdo Flax
06/16/2022, 7:01 AMthanksforallthefish
06/16/2022, 7:13 AMTransactionAutoConfiguration
as well, but if you say that with annotationspec transactions work it is probably not thatthanksforallthefish
06/16/2022, 7:13 AMIdo Flax
06/16/2022, 7:37 AM@DataJpaTest(
properties = [
"spring.application.name=datamatic-tableis-IT",
"spring.cloud.bootstrap.enabled=false",
"atlas.rest.address=<http://localhost:10200>"
]
)
@ImportAutoConfiguration(RefreshAutoConfiguration::class)
@ContextConfiguration(
classes = [HiveConfig::class, TableIsDBConfig::class],
initializers = [DataAccessTestInitializer::class]
)
@ActiveProfiles("integration-test, qa")
@ComponentScan(basePackages = ["com.bla"])
@Transactional
abstract class DataAccessTest : AnnotationSpec(){
override fun extensions() = listOf(SpringExtension)
}
Ido Flax
06/16/2022, 7:38 AMIdo Flax
06/16/2022, 7:39 AM[org.springframework.test.context.transaction.TransactionContext()] - Rolled back transaction for test:
Ido Flax
06/16/2022, 7:42 AMIdo Flax
06/16/2022, 7:51 AMthanksforallthefish
06/16/2022, 8:20 AM