Reputation: 1573
I have a kotlin kotest (formerly known as kotlintest) BehaviorSpec
with one Given("...")
and many When("...") Then("...")
under it
I want to execute a cleanup after the whole Spec (respectively every Given
clause) has finished.
@MicronautTest
class StructurePersistSpec(
private val iC : InstancesC
) : BehaviorSpec({
// afterSpec {
finalizeSpec {
cleanup()
}
Given("...") {
When("...") {
Then("...") {
...
}
Then("...") {
...
}
}
When("...") {
Then("...") {
...
}
Then("...") {
...
}
}
}
...
}
on using afterSpec { }
I get multiple calls (amount of When
s??) to the afterSpec { }
clause and NOT just one after the Spec finished (or finishing of the/each Given
Clause)
on using finalizeSpec { }
it does NOT get called at all (breakpoint inside it is never hit)
what am I doing wrong?
or did I miss some fancy characteristics of BehaviorSpec
s ?
Upvotes: 0
Views: 1709
Reputation: 2408
The reason you are getting multiple calls is that probably you have set a different IsolationMode
for your test.
That would mean your Spec will be recreated (and then cleaned) for every test. In order to have a single afterSpec
call from the framework, your IsolationMode
must be set to SingleInstance
.
Bare in mind that might affect the way your tests are being executed hence their validity or ability to pass.
Documentation: https://kotest.io/isolation_mode/
Upvotes: 2