What's the difference between shouldBe vs shouldEqual in Scala?

半城伤御伤魂 提交于 2020-03-18 10:52:35

问题


When should I be using shouldBe and when should I be using shouldEqual?

port shouldEqual 8000
port shouldBe 8000

回答1:


From http://www.scalatest.org/user_guide/using_matchers#checkingEqualityWithMatchers:

result shouldEqual 3 // can customize equality, no parentheses required

result shouldBe 3 // cannot customize equality, so fastest to compile, no parentheses required

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.



来源:https://stackoverflow.com/questions/43923312/whats-the-difference-between-shouldbe-vs-shouldequal-in-scala

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!