Joel Hess
12/31/2020, 7:41 PM@SpringBootTest
annotation, can I get access to the app context within a specific test? I’m trying to migrate some tests that look like this:
contextRunner.run { context ->
assertThat(context)
.hasSingleBean(MongoCustomConversions::class.java)
}
and change properties on the context for a test?
contextRunner
.withPropertyValues("spring.data.mongodb.migrations.enabled:false")
.run { context ->
assertThat(context)
.doesNotHaveBean(Mongobee::class.java)
}
sam
12/31/2020, 8:08 PMJoel Hess
12/31/2020, 8:08 PMJoel Hess
12/31/2020, 8:11 PM@SpringBootTest()
@ContextConfiguration(classes = [(TestAppConfiguration::class)])
@TestPropertySource(
properties =
[
"spring.profiles.active:unitTests",
"spring.application.name:test-service",
"spring.data.mongodb.uri:<mongodb://username:password@testHost:12,host2:13/testDatabase>"
]
)
class MongoConfigTests : StringSpec() {
override fun listeners() = listOf(SpringListener)
...
}
sam
12/31/2020, 8:15 PMsam
12/31/2020, 8:15 PMsam
12/31/2020, 8:17 PMsam
12/31/2020, 8:17 PMJoel Hess
12/31/2020, 8:18 PMsam
12/31/2020, 8:18 PMsam
01/06/2021, 2:56 PM