Scala中shouldBe和shouldEqual之间有什么区别?

jsh*_*hah 11 scala scalatest

我何时应该使用shouldBe,何时应该使用shouldEqual?

port shouldEqual 8000
port shouldBe 8000
Run Code Online (Sandbox Code Playgroud)

Har*_*ebe 10

来自http://www.scalatest.org/user_guide/using_matchers#checkingEqualityWithMatchers:

结果shouldEqual 3 //可以自定义相等,不需要括号

结果shouldBe 3 //不能自定义相等,因此编译速度最快,不需要括号

第一个采用隐式Equality[T]验证计算值与期望值,第二个不.所以如果你只想比较端口号shouldBe就足够了.