-
Notifications
You must be signed in to change notification settings - Fork 1
How to Test
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()
.
imports for Hamcrest:
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
For asserts use assertThat(actual, 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.
The TestFramework can be used by adding @ExtendWith(FrameworkExtention.class)
.