Giter VIP home page Giter VIP logo

scalamock's Introduction

ScalaMock

Build Status Scaladex Codacy Badge

Native Scala mocking.

Official website: http://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 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

Documentation

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

Donations

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.

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 barkhorn avatar pawel-wiejacha avatar maqdev avatar xuwei-k avatar wangxhere avatar hydra avatar cheeseng avatar valericus avatar sethtisue avatar lj-ditrapani avatar luiz290788 avatar povder avatar dwickern avatar by-dam avatar cb372 avatar backuitist avatar

Watchers

 avatar 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.