Scala 规范:嵌套语句
是否可以将以下规范测试代码嵌套
"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]
}
}
}
因为它更容易阅读和编写
is it possible to nest following specs test code
"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 another in-Statement like:
"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]
}
}
}
Because it is easier to read and write
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。请参阅 http://code.google.com/p/specs/wiki/DeclareSpecifications 概述构建 Specs 规格的所有方法。
Yes. See http://code.google.com/p/specs/wiki/DeclareSpecifications for an overview of all the ways you can structure Specs specifications.
我更喜欢这样的代码:
但正如您可能注意到的,有无数种方法可以做到这一点。
I prefer code like this:
but as you might notice there are a gazillion ways to do it.