O'Reilly logo

Scala Test-Driven Development by Gaurav Sood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Matchers

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required