October 2016
Intermediate to advanced
198 pages
3h 52m
English
Along with assertion, ScalaTest also supports a domain-specific language (DSL) for expressing assertions in the test. This is achieved using the word should. This is done by mixing in Matchers:
import org.scalatest._ class PacktSpec extends FlatSpec with Matchers
Alternatively, members of the trait can be imported explicitly:
import Matchers._
ScalaTest has the Matchers trait, which you can mixin to your suite class to write equality assertions like this:
message should equal ("Hello World")
message is a variable and can be of any type. In all the preceding cases, if the equality is not held true, then TestFailedException is thrown. A detail message encapsulated in this exception will explain the problem and why the test failed.
Alternatively, ...
Read now
Unlock full access