JUnit 5 Fundamentals

This course will teach you how to write unit tests with JUnit 5, covering topics like why unit tests are important, the structure of good unit tests, dynamic and parameterized tests, extensions, code coverage, and more.
Course info
Rating
(26)
Level
Intermediate
Updated
Nov 15, 2017
Duration
3h 7m
Table of contents
Description
Course info
Rating
(26)
Level
Intermediate
Updated
Nov 15, 2017
Duration
3h 7m
Description

An important part of developing high-quality software is testing. As a developer, you're in charge of unit testing your code, and in Java, JUnit is the most popular framework for this task. In this course, JUnit 5 Fundamentals, you'll learn about unit testing in JUnit 5, if you're familiar with JUnit 4 you'll be introduced to the latest features within the new version. First, you'll explore how to create test cases with the new features of JUnit 5. Next, you'll discover how to use dynamic tests. Finally, you'll cover how to implement extensions to create more maintainable tests. By the end of this course, you'll have the necessary knowledge to create unit tests for your projects in JUnit 5.

About the author
About the author

Esteban Herrera has more than twelve years of experience in the software development industry. Having worked in many roles and projects, he has found his passion in programming with Java and JavaScript. Nowadays, he spends all his time learning new things, writing articles, teaching programming, and enjoying his kids.

More from the author
JMeter: Getting Started
Beginner
2h 4m
Apr 29, 2019
Design Patterns in Java: The Big Picture
Beginner
1h 49m
Dec 27, 2018
Mutation Testing in Java with Pitest
Intermediate
2h 0m
Aug 30, 2018
More courses by Esteban Herrera
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone. My name is Esteban Herrera. Welcome to my course, JUnit 5 Fundamentals. I have been working with Java for more than 10 years. I love the language and teaching all I know about it. An important part of developing high-quality software is testing. As a developer, you are in charge of unit testing your code, and in Java, JUnit is the most popular framework for this task. This course is designed for developers who are new to unit testing and want to learn JUnit 5, or already know JUnit 4 and want to learn about the features of the new version. Some of the major topics that we will cover include the new architecture of JUnit 5 and the problem it solves, how to use JUnit to create a static and dynamic test, how to extend JUnit with the new extension mechanism, and how to integrate JUnit with Gradle and Maven. By the end of this course, you'll understand how to use JUnit 5 to write unit tests. Before beginning the course, you should have a basic knowledge of Java 8, streams, lambda expressions, and default methods in interfaces. I hope you'll join me on this journey to learn JUnit 5 with the JUnit 5 Fundamentals course at Pluralsight.

Writing Tests
In this module, you'll learn how to create unit tests with JUnit. I'll start by explaining the structure that good tests have to follow. Next, you'll learn about the lifecycle of a test, then about nested tests to create hierarchies and how to give them custom display names. You'll also learn about assertion methods JUnit provides, how to disable tests, assumptions, how to use interfaces and default methods in tests, and how to repeat a test a specific number of times. After this module, you will have the knowledge to create unit tests for most of your requirements with JUnit 5. Let's get started.

Creating Dynamic and Parameterized Tests
In this module, you'll learn about tests that can be dynamically created at runtime. These tests can be a more powerful alternative to repeated tests. First, you'll learn about dynamic tests that are created with test factories and use collections and streams as input sources. Next, you'll learn about parameterized tests, tests that can be run multiple times with different arguments, in particular, how to configure your product to use them, what you can use as argument sources, and how to handle the conversion from one argument format to another. After this module, you will have the ability to create tests that can be changed at runtime and tests that are driven by data. Let's get started.

Extending JUnit
In this module, you'll learn about JUnit 5 extension model. You'll learn how extensions work and how to implement them using the extension points JUnit provides. For example, how to implement an extension to inject parameters, how to use meta-annotations to make extensions more readable, how to save a state to implement a more complex extension that conditionally execute test, and some examples of extensions developed by the JUnit team. After this module, you'll understand the extension model of JUnit and how to create extensions. So let's get started.

Integrating JUnit 5
Until now, we have used IntelliJ to run our unit test. In this module, you'll learn how to launch the test created in the previous modules from the console, how to run tests with Gradle and Maven using more advanced configuration options, and filter the execution of tests with tags. We'll also take a look at the concept of code coverage, and you'll learn how to configure JaCoCo, a popular Java code coverage library as a plugin for Maven and Gradle to get code coverage reports. After this module, you'll know how to work with JUnit outside an IDE environment and integrated with Gradle and Maven. Let's get started.

Migrating from JUnit 4
In this module, you'll learn some concepts that will help you migrate from JUnit 4 to JUnit 5. First, you'll learn about the API changes between JUnit 4 and JUnit 5, how to run JUnit 4 tests with the JUnit Vintage engine and JUnit Jupiter test in the same project without conflict, and what rules, which are part of the JUnit 4 extension mechanism, are supported in JUnit 5. So let's get started.