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

In former JUnit versions, test constructors and methods were not allowed to have parameters. One of the major changes in JUnit 5 is that both test constructors and methods are now allowed to include parameters. This feature enables the dependency injection for constructors and methods.

As introduced in Chapter 2, What's New In JUnit 5 of this book, the extension model has an extension that provides dependency injections for Jupiter tests, called ParameterResolver, which defines an API for test extensions that wish to dynamically resolve parameters at runtime.

If a test constructor or a method annotated with @Test, @TestFactory, @BeforeEach, @AfterEach, @BeforeAll, or @AfterAll accepts a parameter, that parameter is resolved ...

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