Summary

In this chapter, we introduced the basics of the brand-new programming model of the JUnit 5 framework, known as Jupiter. This programming model provides a rich API that can be used by practitioners to create test cases. The most basic element of Jupiter is the annotation @Test, which identifies the methods in Java classes treated as tests (that is logic which exercises and verifies a SUT). Moreover, there are different annotations that can be used to control the test life cycle, namely, @BeforeAll, @BeforeEach, @AfterEach , and @AfterAll. Other useful Jupiter annotations are @Disabled (to skip tests), @DisplayName (to provide a test name), @Tag (to label and filter tests).

Jupiter provides a rich set of assertions, which are static methods in the class Assertions used to verify if the outcome obtained from the SUT corresponds with some expected value. We can impose conditions for the test execution in several ways. On the one hand, we can use Assumptions to only run tests (or a part of those) if certain conditions are as expected.

We have learned how nested tests can be created simple annotating inner Java classes with @Nested. This can be used to create test executions following an order given the nested classes relationship. We have also studied how easy is to created repeated test using the JUnit 5 programming model. The annotation @RepeatedTest is used to that aim, providing the ability to repeat a test a specified number of times. Finally, we have seen how Jupiter provides support for several legacy JUnit 4 test rules, including ExternalResource, Verifier, and ExpectedException.

In the chapter 4Simplifying Testing With Advanced JUnit Features, we continue discovering the JUnit programming model. Concretely, we review the advance features of JUnit 5, namely, dependency injection, dynamic tests, test interfaces, test templates, parameterized tests, compatibility of JUnit 5 and Java 9. Finally, we review some of the planned features in the backlog for JUnit 5.1, not implemented yet at the time of this writing.

..................Content has been hidden....................

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