The main framework for testing Java code is JUnit.
Junit has gone through several versions.
- As of W21, programming assignments for
MenuItem
andMenu
were based on JUnit 4. - However, Spring Boot legacy code projects are using JUnit 5.
Eventually, the programming assignments for MenuItem
and Menu
will be updated to use JUnit 5 syntax, but for now, it’s helpful to be aware of the differences.
import
statements for JUnit in JUnit4 vs. JUnit 5
The import statements for JUnit 4 look like these (taken from the MenuItem
and Menu
assignments):
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
The import statements for JUnit 5 in a Spring Boot projects look like these:
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.Test;
Testing for Exceptions
This article explains the difference: https://www.baeldung.com/junit-assert-exception