Chapter 4. Simplifying Testing With Advanced JUnit Features
Simplicity is the ultimate sophistication. - Leonardo da Vinci
So far, we have discovered the basics of Jupiter, the brand-new programming model provided by the JUnit 5 framework. Moreover, Jupiter provides a rich range of possibilities which allows to create different types of test cases. In this chapter, we review these advanced features. To that aim, this chapter is structured as follows:
- Dependency injection: This section first takes a look at dependency injection for constructors and methods in test classes. Then, it reviews the three parameter resolvers provided out of the box in Jupiter. These resolvers allow to inject objects of
TestInfo
,RepetitionInfo
, andTestReporter
inside tests. - Dynamic tests: This section discusses how dynamic tests are implemented in JUnit 5, using the methods
dynamicTest
andstream
. - Test interfaces: The section reviews the Jupiter annotations that can be declared on test interfaces and default methods...