When verifying expected value of the scala collection, assertResult
method is convenient:
"The list" should "be generated correctly" in {
assertResult(List(10, 20)) {
//Some code that should output
List(10, 20)
}
}
If something goes wrong, nice error message is generated:
Expected List(10, 20), but got List(10, 30)
Unfortunately, it doesn't work for arrays, because ==
operator checks identity, not equality (The reasons behind this behaviour had been discussed a lot, for example here: Why doesn't Array's == function return true for Array(1,2) == Array(1,2)?).
So, similar check for arrays generates following error message:
Expected Array(10, 20), but got Array(10, 20)
Of cause, it's possible to use should equal
matcher:
"The array" should "be generated correctly" in {
Array(10, 20) should equal {
//Some code that should output
Array(10, 20)
}
}
But IMO it's less convenient, since it's more an equality check that an expectation verification:
Array(10, 20) did not equal Array(10, 30)
Is there an assertion check for arrays in ScalaTest that clearly separates expected result from actual result?