1

是否可以嵌套以下规格测试代码

"ClassX" should {
  "throw an IllegalArgumentException if n < 0" in {
    ClassX(-1) must throwA[IllegalArgumentException]
  }
  "throw an IllegalArgumentException if n > 50" in {
    ClassX(51) must throwA[IllegalArgumentException]
  }
  "throw an IllegalArgumentException if n == 35" in {
    ClassX(35) must throwA[IllegalArgumentException]
  }
}

在另一个 in-Statement 中,例如:

"ClassX" should {
  "throw an IllegalArgumentException if" in {
    "n < 0" in {
      ClassX(-1) must throwA[IllegalArgumentException]
    }
    "n > 50" in  {
      ClassX(51) must throwA[IllegalArgumentException]
    }
    "n == 35" in  {
      ClassX(35) must throwA[IllegalArgumentException]
    }
  }
}

因为它更容易读写

4

2 回答 2

2

是的。请参阅http://code.google.com/p/specs/wiki/DeclareSpecifications以了解构建 Specs 规范的所有方法的概述。

于 2010-10-09T15:57:38.750 回答
0

我更喜欢这样的代码:

 "My Component" >> {
   " some general function" can {
     "do stuff that I like" in {
       //…
     }
     "do stuff others like" in {
       //…
     }
   }
 }

但是您可能会注意到,有无数种方法可以做到这一点。

于 2013-11-06T15:58:15.947 回答