Parameterized Test with two Arguments in JUnit 5 jupiter

Here are two possibilities to achieve these multi argument test method calls. The first (testParameters) uses a CsvSource to which you provide a comma separated list (the delimiter is configurable) and the type casting is done automatically to your test method parameters. The second (testParametersFromMethod) uses a method (provideParameters) to provide the needed data. @ParameterizedTest … Read more

How do I use Hamcrest with JUnit 5 when JUnit 5 doesn’t have an assertThat() function?

You have to make sure Hamcrest is included in the classpath and then use the assertThat() function provided by Hamcrest. From the current JUnit 5 User Guide – Writing Tests Assertions, JUnit Jupiter’s org.junit.jupiter.Assertions class does not provide an assertThat() method like the one found in JUnit 4’s org.junit.Assert class which accepts a Hamcrest Matcher. … Read more

JUnit 5 does not execute method annotated with BeforeEach

In my case the problem was that the @Test annotation was taken from wrong import. Originally it was imported from org.junit.Test. Once I have switched it to org.junit.jupiter.api.Test the problem was resolved. Wrong original code: import org.junit.Test; @BeforeEach …some code @Test …some code Correct fixed code: import org.junit.jupiter.api.Test; @BeforeEach …some code @Test …some code

Mockito gives UnfinishedVerificationException when it seems OK

This might also be caused if you try to verify a method which expects primitive arguments with any(): For example, if our method has this signature: method(long l, String s); And you try to verify it like this, it will fail with aforementioned message: verify(service).method(any(), anyString()); Change it to anyLong() and it will work: verify(service).method(anyLong(), … Read more

Error “TestEngine with ID ‘junit-vintage’ failed to discover tests” with Spring Boot 2.2

I found the error. The dependency on spring-boot-starter-test brings a dependency on junit-vintage-engine. The latter must be excluded: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency>