I have a Scalatest with the following structure which is emasculated within a class
var dataHolder: Holder // some lazy initialization here?
def runTest(filePath: String): Unit = {
//Test 1
it should "load the data holder" in {
loadHolder(filePath)
}
//Test 2
it should "varify the holder is correct" in {
checkHolder(dataHolder)
}
}
Test 1 and 2 are both needs dataHolder
variable, which is generated by function loadHolder( String )
, the loading Holder is I/O and computation intense, therefore I don't want to do it again in Test 2.
I'm looking for a way that both tests can see the variable and the first one is responsible to initialize it, how can I do it? Is there lazy-initialization in Scala?