Lukasz Kalnik
07/21/2023, 8:20 AMViewModel
using BehaviorSpec
, but I want the viewmodel to be a completely new instance for every leaf test (i.e. I want every Given { When { Then
be an independent test).
When using the default isolation mode (SingleInstance
) is it possible to somehow reset the ViewModel for every leaf test?
Or do I have to switch to the isolation mode InstancePerTest
?
I tried InstancePerLeaf
and it seemed like the Given/When
blocks initializations were not taken over correctly into their nested Then
blocks.
InstancePerTest
works correctly for me, but I wanted to take advantage of faster test execution without having to instantiate the class for every test.tieskedh
07/21/2023, 10:58 AMfun <V> Spec.varBeforeTest(
bouwer : () -> V
) = object : ReadWriteProperty<Nothing?,V> {
var waarde : V? = null
init {
beforeTest {
waarde = bouwer()
}
}
override fun getValue(thisRef: Nothing?, property: KProperty<*>): V = waarde as V
override fun setValue(thisRef: Nothing?, property: KProperty<*>, value: V) {
waarde = value
}
}
Emil Kantis
07/21/2023, 6:51 PMtieskedh
07/22/2023, 12:03 AMawaitclose
can be handy. can of course also be another function.