Giter Site home page Giter Site logo

mockito-scala's Introduction

.-=] ABANDONED [=-.

This project is abandoned and not maintained any more, you might want to have a look at https://github.com/mockito/mockito-scala

Mockito Sugar for Scala

Build Status Maven Central

Overview

Inspired by specs2, this is a Scala library that builds on mockito and provides a thin wrapper around the API to make it more pleasurable (and safer) to use in Scala.

This library does not depend on any specific testing framework! Therefore you are free to use it with specs2, ScalaTest or something else.

Why?

The Java API for Mockito is good, but once you are used to some syntactic conveniences from specs2's Mockito trait, it feels very clunky. When using other test frameworks that specs2, there was up until now nothing that provides this form of convenience, therefore this library was written.

This library provides a lightweight Scala DSL around Mockito's Java API. The goals are:

  • more convenient syntax
  • less runtime exceptions on API misuse
  • easy to fall back to Java API when necessary

How?

Add it to your sbt build:

libraryDependencies ++= Seq(
  "org.markushauck" %% "mockitoscala" % "0.3.0"
)

or import it in Ammonite:

import $ivy.`org.markushauck::mockitoscala:0.3.0`

Finally, extend from MockitoSugar trait in your test suite or import all members of the companion object.

Examples!

Please see Examples for an overview of what is currently possible.

Contributing

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.

License

This code is open source software licensed under the Apache 2.0 License.

mockito-scala's People

Contributors

markus1189 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mockito-scala's Issues

Alternative verification API

I don't like giving the mock as an argument to the verification methods, e.g. one(m) in the following snippet from the examples:

there.was.one(m).baz(any[Int])

Maybe something like the following reads more nicely?

m had one(baz(any[Int])) // or maybe received instead of had?

Extend example for `returnMulti`

We should add one more invocation to demonstrate what happens when we invoke more often than the number of given values:

{ // Specifying multiple returns
    val m = mock[Foo]

    m.bar returnsMulti Seq("1", "2", "3")
    m.bar // => "1"
    m.bar // => "2"
    m.bar // => "3"
    m.bar // => "3"
  }

Not sure if "3" is correct, hence my interest in this topic ;-)

Make answering more convenient

In the following snippet from the examples the argument type InvocationOnMock of the function is ugly:

m.baz(any[Int]) answers { (inv: InvocationOnMock) =>
      s"answers: ${inv.getArgument[Int](0) * 2}"
    }

Would it be possible to provide an API which expects a nicely typed function, i.e. Int => A in this case?

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.