Write better tests with

ScalaMock 3

Simple yet powerful native Scala mocking framework.

def testTurtle {
  val mockedTurtle = mock[Turtle]                              // Create mock Turtle object
 
  (mockedTurtle.setPosition _).expects(10.0, 10.0)             //
  (mockedTurtle.forward _).expects(5.0)                        // Set expectations
  (mockedTurtle.getPosition _).expects().returning(15.0, 10.0) // 
 
  drawLine(mockedTurtle, (10.0, 10.0), (15.0, 10.0))           // Exercise System Under Test
}

Features

Simple yet powerful

ScalaMock has very clean and concise syntax, reasonable defaults, powerful features and is fully type-safe.

Full Scala support

Full support for Scala features such as: Polymorphic methods, Operators, Overloaded methods, Type constraints, and more.

ScalaTest and Specs2 integration

ScalaMock can be easily used in ScalaTest and Specs2 testing frameworks.

News

2014-11-12 - ScalaMock 3.2 released

  • improved reporting of unsatisfied expectations (fix for #72)
  • updated, extended and reorganized documentation (created the User Guide and Quick Start)
  • improved support for sharing mocks and expectations by different test cases
  • expectations can be set in Suite scope (fix for #25 and #35)
  • fixed two bugs in scalamock-specs2-support:
    • mocks can be used in threads managed by thread pools (e.g. in Futures)
    • mocks can be defined in fixture-contexts
  • improved support for mocking Java classes:
    • mocking overloaded methods in Java classes (fix for #34)
    • mocking Java classes with bridge methods (fix for #32)
    • mocking Java classes with polymorphic methods (fix for #24)
  • various bug fixes:
    • mocks can be declared as var (fix for #62)
    • mocking methods with Seq[T] parameters (fix for #54)

Documentation