是否可以嵌套以下规格测试代码
"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]
}
}
在另一个声明如下:
"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]
}
}
}
因为它更易于阅读和书写
答案 0 :(得分:2)
是。有关构建规范规范的所有方法的概述,请参阅http://code.google.com/p/specs/wiki/DeclareSpecifications。
答案 1 :(得分:0)
我更喜欢这样的代码:
"My Component" >> {
" some general function" can {
"do stuff that I like" in {
//…
}
"do stuff others like" in {
//…
}
}
}
但是你可能会注意到有很多方法可以做到。