paulbutcher / scalamock

Native Scala mocking framework

Website GitHub


Build Status Scaladex Codacy Badge

Native Scala mocking.

Official website:


Expectations-First Style

test("drawline interaction with turtle") {
  // Create mock Turtle object
  val m = mock[Turtle]
  // Set expectations
  (m.setPosition _).expects(10.0, 10.0)
  (m.forward _).expects(5.0)
  (m.getPosition _).expects().returning(15.0, 10.0)

  // Exercise System Under Test
  drawLine(m, (10.0, 10.0), (15.0, 10.0))

Record-then-Verify (Mockito) Style

test("drawline interaction with turtle") {
  // Create stub Turtle
  val m = stub[Turtle]
  // Setup return values
  (m.getPosition _).when().returns(15.0, 10.0)

  // Exercise System Under Test
  drawLine(m, (10.0, 10.0), (15.0, 10.0))

  // Verify expectations met
  (m.setPosition _).verify(10.0, 10.0)
  (m.forward _).verify(5.0)

A more complete example is on our Quickstart page.


  • 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
  • Mock and Stub support
  • Macro Mocks and Proxy Mocks
  • Scala.js support
  • built for Scala 2.10, 2.11, 2.12

Using ScalaMock

Artefacts are published to Maven Central and JCenter.

For ScalaTest, to use ScalaMock in your Tests, add the following to your build.sbt:

libraryDependencies += "org.scalamock" %% "scalamock" % "4.1.0" % Test


For usage in Maven or Gradle, integration with Specs2, and more example examples see the User Guide


This project is run for fun as a hobby, but if you want to show your appreciation you can donate some ETH or tokens to 0x6A34A63dbD851e4BEC2D25eC7d4E7b50e213C3A7 (QR Code). Or other crypto currencies (Bitcoin, etc) via Shapeshift here. If you want to learn more about Ethereum, visit the homepage or wikipedia.


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.