Scala 中的 shouldBe 与 shouldEqual 有什么区别? [英] What's the difference between shouldBe vs shouldEqual in Scala?
问题描述
什么时候应该使用shouldBe,什么时候应该使用shouldEqual?
When should I be using shouldBe and when should I be using shouldEqual?
port shouldEqual 8000
port shouldBe 8000
推荐答案
来自 http://www.scalatest.org/user_guide/using_matchers#checkingEqualityWithMatchers:
result shouldEqual 3//可以自定义相等,不需要括号
result shouldEqual 3 // can customize equality, no parentheses required
result shouldBe 3//不能自定义相等,所以编译速度最快,不需要括号
result shouldBe 3 // cannot customize equality, so fastest to compile, no parentheses required
第一个采用隐式 Equality[T]
来验证计算值与预期值,第二个没有.所以如果你只是想比较端口号shouldBe
就足够了.
The first one takes an implicit Equality[T]
to verify the computed value with the expected value, the second one doesn't. So if you just want to compare the port number shouldBe
is sufficient.
这篇关于Scala 中的 shouldBe 与 shouldEqual 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!