Mockito, the open source mocking framework for unit tests written in Java, has finally released its version 2, labelled 2.1.0. Mockito 2 demands even cleaner tests remove unnecessary stubs, detect incorrect code with improved argument matchers, use Java 8 answers, and more. In 2016, Mockito has estimated user base of 2M engineers – thank you very much for mocking with us! We greatly value your feedback, feature requests and contributions Mockito 2 contains 700 commits from almost 50 individual contributors.
Since 2014 Mockito continually delivers every merged pull request that passes our rigorous unit and integration tests automatically generates documentation, release notes and artifacts in Maven Central. As much as we are proud our automation and excited about 2.1.0 release we acknowledge our problems undelivered commitments about the final release date, too many beta versions. We will fix this.
Wondering why 2.1.0 instead of 2.0.0? Read about it on our Continuous Delivery page.
The release of Mockito 2 effectively starts Mockito 3 project that focuses on
* full-blown Java 8 support, and Java 9 support (depending on the release date)
* richer stubbing/mocking API (#303)
* improving & extracting the continuous delivery automation to a standalone library (#608) and more!
Help us! We are eager to expand the team and continue improving unit testing experience with mocks. Submit pull requests! See how to contribute. When your PR gets merged, new version of Mockito is published and it is signed with your name in the release notes!
* Changed the mock maker engine from CGLIB to ByteBuddy. This allows Mockito to fix some long standing bugs we had with CGLIB, and pick up byte-code related improvements much quicker (so needed for Java 8 and Java 9). ByteBuddy is a great library and Mockito team is excited to use it now as the default mock-creation engine!
* To avoid Hamcrest version conflicts that our users reported, Mockito does not depend on Hamcrest anymore. There’s still org.mockito.hamcrest.MockitoHamcrest if you need to integrate with Hamcrest.
* Preliminary Java 8 support.
* While Mockito still works with Java 6, it can detect Java 8 runtime and allows
* Mockito JUnit runner and rule can now detect unused stubs. It is possible to revert this behaviour.
* New API for framework integrators and advanced users org.mockito.listeners.MockitoListener. We use this API internally to detect unused stubs.
* Lazy verification is possible with new incubating VerificationCollector Rule
* The default non-lazy way would stop at the verification of simpleMethod and not report the missing verification of byteReturningMethod.
* Improved generics signatures in several places. That should come handy for matchers especially. These methods are more Java 8 friendly. However note that some matchers that helped with generics for Java prior version 8 are now deprecated and will be removed in Mockito 3.
* Better support of generic types in deep stubs
* Mockito can spy abstract classes (with no argument constructor)
* Various improvements from mock injection, to variable printing, code cleanup
* Explore Mockito and especially AdditionalAnswers to find out the change.
* Improved BDDMockito API. Better mirror the Mockito stubbing API (when/then) and augment the BDD API as well
* A bit more friendliness with JUnit 5 via 3rd party extension. The JUnit team developed a JUnit 5 extension, that allows to inject mocks in the test via method parameters
* The extension repository is here and is not managed by the mockito team. Once JUnit 5 goes live we will look into providing built-in integration (in Mockito).
Incompatible changes with 1.10
We tried to minimize the amount of incompatible changes. In order to evolve the library, provide better testing experience, clean up old deprecated code, given the huge adoption of Java 8 and open up for brand new exciting features we need to release a new major version. Incompatible changes like the new anyX() matcher behaviour or detection of unused stubs should actually help with writing cleaner tests!
* Mockito 2 now requires Java 6 as a minimum.
* Mockito does not produce the mockito-all artifact anymore ; this one was primarily aimed at ant users, and contained other dependencies. We felt it was time to move on and remove such artifacts as they cause problems in dependency management system like maven or gradle.
* The Mockito class does not inherit from Matchers class anymore. Instead Mockito and Matchers classes both inherit from ArgumentMatchers. Also Matchers is now deprecated.
* Matchers.argThat method family had a direct dependency on hamcrest, in order to allow matchers to work without Hamcrest we had to move these API to MockitoHamcrest.