-
Book Overview & Buying
-
Table Of Contents
Scala Test-Driven Development
By :
Just like ScalaTest, the Matchers in Specs2 serve the purpose of verifying the results against the expectations. The results of the tests are compared with some expected values, and this is done using Matchers. This is the classic arrange-act-assert archetype.
The most simple example would be a specification for an object that returns the full name of an employee:
// describe the functionality
s2"the getFullName method should return full name of the employee $e1"
// give an example with some code
def e1 = Employee.getFullName() must beEqualTo("Khushboo Maken Sood")
Here, the must operator will take the result returned by the getFullName method and pass it to the Matcher, which in this case is beEqualTo.
Let's look at different types of Matchers in more detail.
We saw an example of this in our last example, that is beEqualTo. This is also the most common type of Matcher.
Here are a few of the syntaxes of equality Matchers:
|
Matcher |
... |