1

有时我们需要在测试用例中混入一些特征。但是以下方法不起作用:

"abc" should {
  "def" in new TraitA with TraitAB {
    // ...
  }    
}

为了使其工作,我们执行以下操作:

trait Fixture extends Before {
  def before = ()
}

"abc" should {
  "def" in new Fixture with TraitA with TraitAB {
    // ...
  }    
}

这感觉有点hacky。有更好的方法吗?

4

1 回答 1

3

如果您还混合了org.specs2.specification.Scope标记特征,这将起作用:

"abc" should {
  "def" in test {
    // ...
  }    
}

trait test extends TraitA with TraitAB with Scope
于 2013-04-29T06:19:34.027 回答