0PricingLogin
Scala for Backend Engineering & Functional Programming · Lesson

Matchers

Expressive assertions.

What are Matchers?

ScalaTest matchers provide an expressive, English-like syntax for assertions. Instead of assert(x == 3), you write x shouldBe 3, producing readable tests and clear failure messages.

Mixing in Matchers

Mix the Matchers trait into your spec to unlock the DSL. It combines with any testing style.

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class DemoSpec extends AnyFlatSpec with Matchers {
  "A value" should "equal itself" in {
    val x = 3
    x shouldBe 3
  }
}

All lessons in this course

  1. ScalaTest Styles
  2. Matchers
  3. Property-Based Testing
  4. Mocking and Fixtures
← Back to Scala for Backend Engineering & Functional Programming