Native Scala mocking
This page describes ScalaMock 3, which supports Scala 2.10 only. For earlier versions of Scala, see
ScalaMock 2.
Expectations-First Style
Record-then-Verify (Mockito) Style
Full worked example.
Features
- Fully typesafe
- Full support for Scala features such as:
- Polymorphic (type parameterised) methods
- Operators (methods with symbolic names)
- Overloaded methods
- Type constraints
- ScalaTest and Specs2 integration
Downloading
Download from Sonatype.
To use ScalaMock in sbt with ScalaTest add the following to your project file:
and with Specs2:
The source is hosted on GitHub.
Documentation
Scaladoc.
Future Plans
When Scala supports macro types, this will enable:
-
Improved syntax:
instead of:
- Mocking object creation (constructors)
- Mocking singleton and companion objects (static methods)
- Mocking final classes and classes with final methods or private constructors
Acknowledgements
YourKit is kindly supporting open source projects with its full-featured Java Profiler.
YourKit, LLC is the creator of innovative and intelligent tools for profiling
Java and .NET applications. Take a look at YourKit's leading software products:
YourKit Java Profiler and
YourKit .NET Profiler.