O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JUnit 5 extension for Mockito

At the time of this writing, there is no official JUnit 5 extension to use Mockito in Jupiter tests. Nevertheless, the JUnit 5 team provides a simple ready to use Java class implementing a simple but effective extension for Mockito. This class can be found in the JUnit 5 user guide (http://junit.org/junit5/docs/current/user-guide/), and its code is the following:

import static org.mockito.Mockito.mock;import java.lang.reflect.Parameter;import org.junit.jupiter.api.extension.ExtensionContext;import org.junit.jupiter.api.extension.ExtensionContext.Namespace;import org.junit.jupiter.api.extension.ExtensionContext.Store;import org.junit.jupiter.api.extension.ParameterContext;import org.junit.jupiter.api.extension.ParameterResolver; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required