October 2016
Intermediate to advanced
198 pages
3h 52m
English
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 ...
Read now
Unlock full access