Custom Matchers

Learn how to define your own matchers to extend ScalaTest DSL.

In this lesson, we’ll take a look at custom matchers. We’ll start off by refining the way we use property and boolean matchers and then define our own.

Property matchers

We can define custom property matchers by creating instances of the HavePropertyMatcher trait. ScalaTest documentation advises doing this in a trait we can later mix into our test classes. The following snippet of code defines custom matchers for Course#title, Course#author, and PaidCourse#price.

Get hands-on with 1200+ tech skills courses.