Giter Club home page Giter Club logo

scalamock's Introduction

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.

scalamock's People

Contributors

paulbutcher avatar pawel-wiejacha avatar backuitist avatar cb372 avatar dwickern avatar cheeseng avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.