Some trouble with JUnit 5 and solution

Yesterday had a pretty weird issue with Junit 5 which didn’t compile. Spent half a day trying to tweak pom file, specify specific directory and making sure I have proper scope and such.

Funniest thing tests were working from eclipse, but from CLI both tests and package compilation fails.

Turns out Eclipse was using incorrect import directives from Junit 4 (which was not referenced in POM) and those imports worked!!!

Specifically those:

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

Replacing those imports with proper Junit 5 ones did the trick:

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Leave a comment

Your email address will not be published. Required fields are marked *