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

Dependency injection

The ParameterResolver extension provides dependency injection at method level. In this example, we can see how an argument is injected in the test method with a custom implementation of ParameterResolver called MyParameterResolver. Following the code, we can see that this resolver will simply inject hard-coded String parameters with the value my parameter:

package io.github.bonigarcia;import org.junit.jupiter.api.extension.ExtensionContext;import org.junit.jupiter.api.extension.ParameterContext;import org.junit.jupiter.api.extension.ParameterResolutionException;import org.junit.jupiter.api.extension.ParameterResolver;public class MyParameterResolver implements ParameterResolver {    @Override    public boolean supportsParameter(ParameterContext ...

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