是否可以在spek2测试的一个主要组中的测试与组之间共享测试状态? 因此,我进行了以下测试:
internal object IntegrationTest : Spek({
val testState by memoized(CachingMode.SCOPE) { TestState() }
group("Test for ${level}") {
assertThat(level).describedAs("The level have to be set").isNotNull()
test("Login") {
assertThat("test").isNotBlank()
testState.state = "SUCCESS"
}
group("Test user profile") {
assertThat("test2").isNotBlank()
val username = getUsername()
testState.username = ec2Username
}
}
})
testState 在 test(“ Login”)中可用,但是对于 group(“ Test user profile”),我得到了错误:
'testState' can not be accessed in this context.
java.lang.AssertionError: 'testState' can not be accessed in this context.
at org.spekframework.spek2.runtime.lifecycle.MemoizedValueAdapter.get(MemoizedValueAdapter.kt:33)
at org.spekframework.spek2.runtime.lifecycle.MemoizedValueAdapter.getValue(MemoizedValueAdapter.kt:22)
at com.advantest.swdp.cloudintegration.SWCIntegrationTest$1$1$1$2.invoke(IntegrationTest.kt:33)
at com.advantest.swdp.cloudintegration.SWCIntegrationTest$1$1$1$2.invoke(IntegrationTest.kt:15)
at org.spekframework.spek2.runtime.Collector.group(Collectors.kt:91)
...
是否可以在测试和组之间共享状态?怎么了?
最好的问候