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, and TestReporter inside tests.
  • Dynamic tests: This section discusses how dynamic tests are implemented in JUnit 5, using the methods dynamicTest and stream.
  • Test interfaces: The section reviews the Jupiter annotations that can be declared on test interfaces and default methods.
  • Test templates: JUnit 5 introduces the concept of a template for tests cases. These templates will be invoked multiple times, depending on the invocation contexts.
  • Parameterized tests: In the same way as JUnit 4, JUnit 5 provides capabilities to create tests driven by different input data, that is, a parametrized test. We will discover that the support for this kind of test has been significantly enhanced in the Jupiter programming model.
  • Java 9: On September 21, 2017, Java 9 released. As we will discover, JUnit 5 has been implemented to be compatible with Java 9, with special emphasis on the modularity feature of Java 9.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.184.200