【问题标题】:Creating a fixture in Specs 2在 Specs 2 中创建夹具
【发布时间】:2013-04-29 05:45:09
【问题描述】:

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

"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。有没有更好的方法?

【问题讨论】:

    标签: scala testing specs


    【解决方案1】:

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

    "abc" should {
      "def" in test {
        // ...
      }    
    }
    
    trait test extends TraitA with TraitAB with Scope
    

    【讨论】:

      猜你喜欢
      • 2013-05-26
      • 2011-07-09
      • 2022-06-17
      • 2019-10-02
      • 2014-04-22
      • 1970-01-01
      • 2013-09-02
      • 2022-06-16
      • 2011-09-03
      相关资源
      最近更新 更多