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 ...
Get Scala Test-Driven Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.