Book Image

Mastering Software Testing with JUnit 5

By : Boni Garcia
Book Image

Mastering Software Testing with JUnit 5

By: Boni Garcia

Overview of this book

When building an application it is of utmost importance to have clean code, a productive environment and efficient systems in place. Having automated unit testing in place helps developers to achieve these goals. The JUnit testing framework is a popular choice among Java developers and has recently released a major version update with JUnit 5. This book shows you how to make use of the power of JUnit 5 to write better software. The book begins with an introduction to software quality and software testing. After that, you will see an in-depth analysis of all the features of Jupiter, the new programming and extension model provided by JUnit 5. You will learn how to integrate JUnit 5 with other frameworks such as Mockito, Spring, Selenium, Cucumber, and Docker. After the technical features of JUnit 5, the final part of this book will train you for the daily work of a software tester. You will learn best practices for writing meaningful tests. Finally, you will learn how software testing fits into the overall software development process, and sits alongside continuous integration, defect tracking, and test reporting.
Table of Contents (8 chapters)

What this book covers

Chapter 1, Retrospective On Software Quality And Java Testing, provides a detailed review of software quality and testing. The objective of this chapter is to clarify the terminology of this domain in an intelligible way. Moreover, this chapter provides a summary the history of JUnit (version 3 and 4) and also some JUnit enhancers (for example, libraries that can be used to extend JUnit).

Chapter 2, What’s New In JUnit 5, first introduces the motivation to create a version 5 of JUnit. Then, this chapter describes the main components of the JUnit 5 architecture, namely, Platform, Jupiter, and Vintage. Next, we discover how to run JUnit tests, for example, using different build tools such as Maven or Gradle. Finally, this chapter is the extension model of JUnit 5, which allows extending the core functionality of JUnit 5 by any third party.

Chapter 3, JUnit 5 Standard Tests, gives a detailed description of the basic features of the new JUnit 5 programming model. This programming model, together with the extension model, is called Jupiter. In this chapter, you learn about the basic test lifecycle, assertions, tagging and filtering tests, conditional test execution, nested and repeated tests, and finally how to migrate from JUnit 4.

Chapter 4, Simplifying Testing With Advanced JUnit Features, provide a detailed description of the JUnit 5 features, such as dependency injection, dynamic tests, test interfaces, test templates, parameterized tests, compatibility with Java 9, and planned features for the for JUnit 5.1 (not released yet at the time of this writing).

Chapter 5, Integration Of JUnit 5 With External Frameworks, talks about the integration of JUnit 5 with existing third-party software. This integration can be done in different ways. Typically, the Jupiter extension model should be used to interact with external frameworks. This is the case of Mockito (a popular mock framework), Spring (a Java framework aimed to created enterprise applications based on dependency injection), Docker (a container platform technology), or Selenium (test framework for web applications). In addition, developers can reuse to Jupiter test lifecycle to interact with other technologies, for example, Android or REST services.

Chapter 6, From Requirements To Test Cases, provides a set of best practices aimed to help a software tester to write meaningful test cases. Considering the requirements as the basis of software testing, this chapter provides a comprehensive guide for coding tests avoiding typical mistakes (anti-patterns and code smell).

Chapter 7, Testing Management, is the final chapter of the book, and its objective is to guide the reader to understand how software testing activities are managed in a living software project. To that aim, this chapter reviews concepts such as Continuous Integration (CI), build servers (Jenkins, Travis), test reporting, or defect tracking systems. To conclude the book, a complete example application together with different types of tests (unit, integration, and end-to-end) is presented.