Scala 规范:嵌套语句

发布于 2024-09-27 10:04:21 字数 785 浏览 0 评论 0原文

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

"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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗笺 2024-10-04 10:04:21

是的。请参阅 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.

荒人说梦 2024-10-04 10:04:21

我更喜欢这样的代码:

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

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

I prefer code like this:

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

but as you might notice there are a gazillion ways to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文