• Home
  • Search Tags
  • About

mockito

Topics related to mockito:

Getting started with mockito

Mockito is a java Mocking framework that aims at providing the ability to write clean an readable unit tests by using it's simple API. It differs from other mocking frameworks by leaving the expect-run-verify pattern that most other frameworks use.

Instead it only knows one way to mock (non-final) classes and interfaces and allows to verify and stub based on flexible argument matchers.

The current Version 1.10.19 is best obtained using maven

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>1.10.19</version>
</dependency>

or gradle

repositories { jcenter() }
dependencies { testCompile "org.mockito:mockito-core:1.+" }

Version 2 is still in beta.

Mock

Mockito Best Practices

Verify method calls

Mocking consecutive calls to a void return method

Remember, for non-void methods, the when(mock.method()).thenThrow().thenReturn() version (see docs) is preferred because it is argument type-safe and more readable.

Mock final classes and methods

Content on the page is taken from Stack Overflow Documentation

This site is NOT affiliated with Stack Overflow or any of the contributors. | Privacy Policy | Terms of Service