Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This page describes how we can write our first test class with JUnit 5. After we have finished this blog postpage, we:

  • Can create test classes with JUnit 5.
  • Know how we can use setup and teardown methods.
  • Understand how we can write simple test methods with JUnit 5.

...

Info

The tutorial repository can be found here:

https://gitlab.eufus.psnc.eupl/bpogodzinskiach/ach-tutorials/-/tree/TDD-java/TDD-java/Overview

Setup and Teardown methods

...

  • The method that is annotated with the @BeforeAll annotation must be static, and it's run once before any test method is run.
  • The method that is annotated with the @BeforeEach is invoked before each test method.
  • The method that is annotated with the @AfterEach annotation is invoked after each test method.
  • The method that is annotated with the @AfterAll annotation must be static, and it's run once after all test methods have been run.

...

This tutorial has taught us four three things:

...

  • Setup and teardown methods must not be private and they must not return anything.
  • A test method is a method that isn't private and doesn't return anything.
  • We could specify the display name of a test class and a test method because this allows us to replace technical names with sentences that make sense.