mockito Getting started with mockito Installation and setup



The preferred way to install Mockito is to declare a dependency on mockito-core with a build system of choice. As of July 22nd, 2016, the latest non-beta version is 1.10.19, but 2.x is already encouraged to be migrated to.




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

There is also mockito-all which contains Hamcrest and Objenesis besides Mockito itself. It is delivered through Maven mainly for ant users, but the distribution has been discontinued in Mockito 2.x.


The most of the Mockito facilities are static methods of org.mockito.Mockito. Thus, Mockito can be statically imported into a class in this way:

import static org.mockito.Mockito.*;

Documentation entry point is located in the javadoc of this class.