我有如下最大规模的代码:
class myTest extends FlatSpec with ParallelTestExecution {
val testSuiteId: String = GenerateSomeRandomId()
it should "print test id" in {
println(testSuiteId)
}
it should "print test id again" in {
println(testSuiteId)
}
}
这两个测试无法打印我在它们之前生成的 testSuiteId。相反,他们会重新生成 ID 并打印出来。我知道,由于 ParallelTestExecution 扩展了 OneInstancePerTest,这里的每个测试都在自己的实例上运行,并拥有变量“testSuiteId”的副本。
但是我确实想要这个测试套件的固定 ID,并且这个套件中的每个测试用例都可以访问它而不修改它。我试图在 BeforeAll{ } 中创建固定的 id,但它仍然没有用。
我应该如何实现我想要的?