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

1

22

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

port shouldEqual 8000
port shouldBe 8000
Permute answered 11/5, 2017 at 18:42 Comment(0)
A
18

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.

Avoirdupois answered 11/5, 2017 at 18:55 Comment(1)
" "should be" and shouldBe will likely be the fastest-compiling matcher syntax for equality comparisons, since the compiler need not search for an implicit Equality[T] each time." (from the same link)Camarillo

© 2022 - 2024 — McMap. All rights reserved.