Skip to content

dvic/ScalaMock

This branch is 494 commits behind ScalaMock/ScalaMock:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Damir Vandic
Aug 3, 2016
9b31642 · Aug 3, 2016
Apr 14, 2015
Aug 3, 2016
Feb 6, 2015
Aug 3, 2016
Aug 3, 2016
Jan 11, 2013
May 24, 2014
Apr 20, 2015
Dec 4, 2014
Jan 11, 2013
Jun 26, 2012

Repository files navigation

ScalaMock Build Status

Native Scala mocking.

Official website: http://scalamock.org/

Examples

Expectations-First Style

def testTurtle {
  val m = mock[Turtle]                              // Create mock Turtle object

  (m.setPosition _).expects(10.0, 10.0)             //
  (m.forward _).expects(5.0)                        // Set expectations
  (m.getPosition _).expects().returning(15.0, 10.0) // 

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

Record-then-Verify (Mockito) Style

def testTurtle {
  val m = stub[Turtle]                              // Create stub Turtle
  
  (m.getPosition _).when().returns(15.0, 10.0)      // Setup return values

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

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

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:

libraryDependencies +=
  "org.scalamock" %% "scalamock-scalatest-support" % "3.2.2" % "test"

and with Specs2:

libraryDependencies +=
  "org.scalamock" %% "scalamock-specs2-support" % "3.2.2" % "test"

Documentation

Future Plans

Check our roadmap.

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.

About

Native Scala mocking framework

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 98.5%
  • Java 1.5%