【问题标题】:Execute a before/after each in a specified should block out of many in Specs2在 Specs2 中的每个指定应该阻止许多之前/之后执行
【发布时间】:2015-05-22 20:56:28
【问题描述】:

我有一个像下面这样写的规范:

class MySpec extends Specification {

  "A" should {
    "be true" in {
      true must beEqualTo(true)
    }
  }

  "B" should {
    "be false" in {
      false must beEqualTo(false)
    } 
  }
  ...
}

我如何/我可以为 each 测试指定仅在 "B" 块(例如)内执行的 before/after 语句。

【问题讨论】:

    标签: scala specs2


    【解决方案1】:

    您可以为您的测试创建一个上下文:

    trait Context extends BeforeAfter {
      def before: Any = println("Doing setup")
      def after: Any = println("Done. Cleanup")
    }
    
    "B" should {
      "be false" in new Context  {
        false must beEqualTo(false)
       }
    }
    

    如果您需要使用 specs2 做一些棘手的事情,可以查看 this link

    【讨论】:

      猜你喜欢
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      相关资源
      最近更新 更多