A deep dive into JUnit 5
JUnit 5 is a novel testing framework that provides a new programming and extension model called Jupiter. This workshop reviews the JUnit 5's architecture and the main features of Jupiter
Max 100 attendees
testing-tools, test-cases, automation
By the end of this course, you'll be able to:
- Describe the modular architecture of JUnit 5
- Execute basic test cases with JUnit 5
- Develop advanced test cases using Jupiter
Version 5 of the popular testing framework JUnit was first released in September 2017. Since then, JUnit 5 is in constant evolution and maintenance. It has been designed using a modular architecture made up of three main components:
- Platform: Foundation component providing generic capabilities to discover and execute test cases in a Java Virtual Machine (JVM).
- Vintage: Engine for legacy tests (JUnit 3 and 4).
- Jupiter: Engine for the new programming and extension model.
Jupiter tests can be executed using a build tool such as Maven, Gradle, or Ant. Besides, modern Integrated Development Environments (IDEs) such as IntelliJ IDEA, Eclipse, or Visual Studio, are shipped with built-in capabilities to execute JUnit tests out of the box.
Java annotations are one of the main building blocks of the Jupiter programming and extension model. For instance, we can specify the logic to exercise and verify a System Under Test (SUT), i.e., a test case (or simply test), using the annotation @Test at method-level in a Java class. Other basic annotations to define the rest of the basic test lifecycle are @BeforeEach/@BeforeAll (setup logic, executed before the test) and (@AfterEach/@AfterAll (teardown logic, executed after the test). When coming to data verification, Jupiter provides a rich API for assertions (e.g., assertTrue, assertFalse, assertEquals, assertArrayEquals, among many others). Besides, we can use a third-party advanced assertions library in conjunction with Jupiter, for example, Hamcrest, Truth, or AssertJ, to name a few.
Jupiter provides a wide variety of additional features to develop different types of tests. In this workshop, we review some of the most relevant, namely:
- Tagging and filtering: Label and execute a group of tests.
- Timeout: Specify a configurable time for a test to fail.
- Test order: Specify a given execution order for tests.
- Parameterized tests: Implement data-driven tests.
- Parallel execution: Use a thread-pool to execute a test suite in parallel.
Finally, we introduce the extension model of Jupiter. An extension in Jupiter is a Java class that allows developers to incorporate extra features to Jupiter. The building block of the Jupiter extension model is the so-called extension points, such as:
- Lifecycle callbacks and test instance postprocessing: to enhance the default test lifecycle with custom logic.
- Conditional test execution: to custom enable/disable tests.
- Parameter resolution: to implement dependency injection in tests.
- Exception handling: for custom exception manipulation.
The tentative table of contents for this workshop is the following:
2. JUnit 5 overview
3. Basic tests
- Test lifecycle
- Test execution
- Other basic annotations
4. Advanced tests
- Tagging and filtering
- Test order
- Parameterized tests
- Parallel execution
5. Extension model
- Extension points
- Test templates
6. Other features
- Migration from JUnit 4
- Dynamic tests
- Test interfaces
- Integration with other frameworks
- Further doc
Meet the Instructor
I am Assistant Professor at Universidad Carlos III de Madrid (UC3M) in Spain. I teach several courses in software engineering and computer networks. My research interests include software testing, web engineering, and cloud computing. I am the author of more than 35 research papers in different journals, magazines, and international conferences. In 2017 I wrote the book Mastering Software Testing with JUnit 5, edited by Packt Publishing. I am an open-source software enthusiast, contributing to different projects. I am the maintainer of the projects WebDriverManager and Selenium-Jupiter, among others.