【发布时间】:2016-12-14 13:21:57
【问题描述】:
我有许多测试文件,每个文件都有自己的测试。到目前为止,每个人都有一个我创建配置对象的特征。
现在构建该对象需要两分钟的大部分时间,因为它必须做大量工作来调用许多数据库(不要问 - 真的,它必须完成)。
有没有办法在多个文件中的多个测试套件之间共享这个对象(下面的 tldConfigMap),而不必一遍又一遍地构建它?
这就是我的做法 - 正如你所看到的,当作为 trait 引入时,每次都会调用 load():
trait TLDMapAcceptanceIsLoadedSpec extends org.scalatest.fixture.FlatSpecLike with TLDConfigMap {
val tldConfigMap: Map[String, TLDConfig] = load(withAttributes = true).right.get
type FixtureParam = Map[String, TLDConfig]
def withFixture(test: OneArgTest) = {
withFixture(test.toNoArgTest(tldConfigMap)) // "loan" the fixture to the test
}
}
【问题讨论】:
-
答案评论中提到的小repro似乎从未到达。我建议将其关闭。