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

ScalaMock

ScalaMock was perhaps the first mocking framework which understood that Scala is a different language than Java. It played on the fact that Scala allows both functional and object-oriented code. Therefore, the mocking framework for Scala needs to be able to mock both these as aspects of a Scala class.

It is a native framework and it allows mocking of both functions and objects. Paul Butcher wrote Scala mock.

Advantages of ScalaMock

  • Type safe
  • Open source
  • Support for Scala-specific features such as:
    • Operator methods
    • Method overloading
    • Pattern matching
    • Parameterized methods

  • Compatible with both ScalaTest and Specs2

We need to mix MockFactory into our test suite for us to be able to use ScalaMock with ScalaTest, as per the following example:

import ...

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