segrada
segrada copied to clipboard
Migrate to JUnit Jupiter
This PR upgrades the project to use the modern JUnit Jupiter 5.9.1 instead of the outdated JUnit 4.13.1 in order to make it easier for future contributors to write and maintain unit tests in the project.
Note: While this patch doesn't contain any significant logic, it's already quite large. In an attempt to keep it as easy as possible to review, it was kept minimal and only replaces JUnit 4 constructs with JUnit Jupiter constructs. With JUnit Jupiter in place, some obvious improvements/cleanups are available, but they will be performed in a followup patch.
This PR includes:
- pom.xml
- The
junit:junit:4.13.1
dependency was replaced with the modernorg.junit.jupiter:junit-jupiter:5.9.1
dependency - An explicit definition of
maven-surefire-plugin:2.22.2
was introduced instead of the implicit2.12
version that was not specified in order to be able to execute JUnit Jupiter tests. -
maven-dependency-plugin
'sexcludeArtifactIds
configuration was updated to excludejunit-jupiter
instead ofjunit
- The
- Annotations
-
org.junit.jupiter.api.Test
was used as a drop-in replacement fororg.junit.Test
in the simple case where no arguments were used with the annotation. In the case where theexpected
argument was used this annotation was still used, but the assertions in the test had to be modified, see 3.iii below -
org.junit.jupiter.api.BeforeEach
was used as a drop-in replacement fororg.junit.Before
. -
org.junit.jupiter.api.BeforeAll
was used as a drop-in replacement fororg.junit.BeforeClass
. -
org.junit.jupiter.api.AfterEach
was used as a drop-in replacement fororg.junit.After
. -
org.junit.jupiter.api.AfterAll
was used as a drop-in replacement fororg.junit.AfterClass
. - In the cases where multiple annotations were replaced in the same class, imports were reorganized to keep their alphabetical order.
-
- Assertions
-
org.junit.jupiter.api.Assertions
' methods were used as drop-in replacements fororg.junit.Assert
's methods with the same name in the simple case where the method was used without the extra message argument. - In the cases where an
org.junit.Assert
method was used with the extra message argument it was replaced with a call to anorg.junit.jupiter.api.Assertions
method with the same name, and the arguments were rearranged so that the message argument would be last instead of first. -
org.junit.jupiter.api.Assertions
'assertThrows
was used to test expected exceptions being thrown whereorg.junit.Test
was used with theexpected
argument.
-