There are three default assertions that come out of the box with ScalaTest:
assert
:We used this in Chapter 2, First Test-Driven Application. This is used for general assertions:
test("one plus one") { assert(1 + 1 == two) assert(1 + 1 != three) }
assertResult
:This is used to differentiate between the expected value and the actual:
test("one plus one with result") { val two = 2 assertResult(two) { 1 + 1 } }
intercept
:We have seen the use of intercept in Chapter 2, First Test-Driven Application. This is useful in cases when we want to test if a method throws an expected exception:
intercept[IllegalArgumentException] { someMethod() }
The equivalent JUnit 3 like implementation would be:
try { someMethod() fail("Shouldn't be here") } catch { case _:IllegalArgumentException...