Code Monkey home page Code Monkey logo

scalamock's Introduction

ScalaMock

Native Scala mocking.

Official website: scalamock.org

Examples

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.

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
  • Mock and Stub support
  • Macro Mocks and JVM Proxy Mocks
  • Scala.js support
  • built for Scala 2.11, 2.12, 2.13
  • Scala 2.10 support was included up to ScalaMock 4.2.0

Using ScalaMock

Artefacts are published to Maven Central and Sonatype OSS.

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

libraryDependencies += Seq("org.scalamock" %% "scalamock" % "5.2.0" % Test,
    "org.scalatest" %% "scalatest" % "3.2.0" % Test)

Documentation

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

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.

Many thanks to Jetbrains for providing us with an OSS licence for their fine development tools such as IntelliJ IDEA.

Also, thanks to https://github.com/fthomas/scala-steward for helping to keep our dependencies updated automatically.

scalamock's People

Contributors

backuitist avatar barkhorn avatar by-dam avatar cb372 avatar cheeseng avatar ddworak avatar dodnert avatar dwickern avatar hhimanshu avatar hydra avatar lj-ditrapani avatar luiz290788 avatar maqdev avatar mirko-manojlovic-htec avatar mkasberg avatar nimatrueway avatar paulbutcher avatar pawel-wiejacha avatar philippus avatar povder avatar scala-steward avatar sethtisue avatar sullis avatar valericus avatar wangxhere avatar xuwei-k 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.