Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

How to Test

Leon Kiefer edited this page Jun 20, 2018 · 3 revisions

JUnit 5 and JUnit Jupiter

We are using JUnit 5 as test platform. For better assertions and matchers we are using Hamcrest. Use assertThat(actual, matcher) instead of assertEquals(). For mocking classes and interfaces we are using mockito. It allows us to test code without the need to run the whole application.

Import for JUnit Jupiter:

import static org.junit.jupiter.api.Assertions.assertThrows;

only requiered if testing Exceptions with assertThrows().

Hamcrest

imports for Hamcrest:

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

For asserts use assertThat(actual, matcher).

Matcher

Matchers are used to check the assertion conditons on the actual value. There are simple matcher like is(value) or equalTo(operand) and matcher which combine matchers like not(matcher) or allOf(matchers...). For a list of matchers see this list, but that's not all, there are many libraries and you can create matchers your self.

How to use the TestFramework

The TestFramework can be used by adding @ExtendWith(FrameworkExtention.class).