The Difference Between mockito-core and mockito-all – mockito-core和mockito-all之间的区别

最后修改: 2020年 4月 24日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

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

Mockito是一个流行的Java的嘲弄框架。但是,在我们开始之前,我们有一些不同的神器可以选择。

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.

在这个快速教程中,我们将探讨mockito-coremockito-all之间的区别。之后,我们将能够选择正确的一个。

2. mockito-core

2.mockito-core

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

mockito-core工件是Mockito的主要工件。具体而言,它包含API和库的实现。

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

我们可以通过在我们的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.

在这一点上,我们已经可以开始使用Mockito

3. mockito-all

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.

当然,mockito-core有一些依赖,如hamcrestobjenesis,Maven会单独下载,但mockito-all一个过时的依赖,捆绑了Mockito以及它所需的依赖

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

为了验证这一点,让我们看看mockito-all.jar的内部,看看它包含的软件包。

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.

mockito-all的最新GA版本是2014年发布的1.x版本。新版本的Mockito不再发布mockito-all

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

4.总结

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.

正如我们上面所探讨的,mockito-core是Mockito的主要工件。新版本不再发布mockito-all了。因此,我们应该只使用mockito-core.