If I spin up a Spec with the `@SpringBootTest` ann...
# kotest
j
If I spin up a Spec with the
@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:
Copy code
contextRunner.run { context ->
   assertThat(context)
      .hasSingleBean(MongoCustomConversions::class.java)
}
and change properties on the context for a test?
Copy code
contextRunner
    .withPropertyValues("spring.data.mongodb.migrations.enabled:false")
    .run { context ->
        assertThat(context)
            .doesNotHaveBean(Mongobee::class.java)
    }
s
Are you using the kotest spring listener ?
j
Yes
I have this as my setup
Copy code
@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)
...
}
s
The test context is not made available
but it would be easy to do so
will include it in 4.4
j
Thanks for the quick response!
s
no problem. If you can't wait for 4.4 you would need to copy that SpringTestListener class and adapt it.