Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE

1. Overview

Mockito is a popular mocking framework for Java. But, before we start, we have some different artifacts to choose from.

In this quick tutorial, we’ll explore the difference between mockito-core and mockito-all. Afterward, we’ll be able to choose the right one.

2. mockito-core

The mockito-core artifact is Mockito’s main artifact. Specifically, it contains both the API and the implementation of the library.

We can obtain the artifact by adding the dependency to our pom.xml:

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

At this point, we can already start using Mockito.

3. mockito-all

Of course, mockito-core has some dependencies like hamcrest and objenesis that Maven downloads separately, but mockito-all is an out-dated dependency that bundles Mockito as well as its required dependencies.

To verify this, let’s look inside the mockito-all.jar to see the packages it contains:

mockito-all.jar
|-- org
|   |-- hamcrest
|   |-- mockito
|   |-- objenesis

The latest GA version of mockito-all is a 1.x version released in 2014. Newer versions of Mockito don’t release mockito-all anymore.

The maintainers released this dependency as a simplification. Developers were supposed to use this if they don’t have a build tool with dependency management.

4. Conclusion

As we explored above, mockito-core is the main artifact of Mockito. Newer versions don’t release mockito-all anymore. Henceforth, we should only use mockito-core.

Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – REST with Spring (eBook) (everywhere)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.