segrada icon indicating copy to clipboard operation
segrada copied to clipboard

Migrate to JUnit Jupiter

Open mureinik opened this issue 2 years ago • 0 comments

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:

  1. pom.xml
    1. The junit:junit:4.13.1 dependency was replaced with the modern org.junit.jupiter:junit-jupiter:5.9.1 dependency
    2. An explicit definition of maven-surefire-plugin:2.22.2 was introduced instead of the implicit 2.12 version that was not specified in order to be able to execute JUnit Jupiter tests.
    3. maven-dependency-plugin's excludeArtifactIds configuration was updated to exclude junit-jupiter instead of junit
  2. Annotations
    1. org.junit.jupiter.api.Test was used as a drop-in replacement for org.junit.Test in the simple case where no arguments were used with the annotation. In the case where the expected argument was used this annotation was still used, but the assertions in the test had to be modified, see 3.iii below
    2. org.junit.jupiter.api.BeforeEach was used as a drop-in replacement for org.junit.Before.
    3. org.junit.jupiter.api.BeforeAll was used as a drop-in replacement for org.junit.BeforeClass.
    4. org.junit.jupiter.api.AfterEach was used as a drop-in replacement for org.junit.After.
    5. org.junit.jupiter.api.AfterAll was used as a drop-in replacement for org.junit.AfterClass.
    6. In the cases where multiple annotations were replaced in the same class, imports were reorganized to keep their alphabetical order.
  3. Assertions
    1. org.junit.jupiter.api.Assertions' methods were used as drop-in replacements for org.junit.Assert's methods with the same name in the simple case where the method was used without the extra message argument.
    2. In the cases where an org.junit.Assert method was used with the extra message argument it was replaced with a call to an org.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.
    3. org.junit.jupiter.api.Assertions' assertThrows was used to test expected exceptions being thrown where org.junit.Test was used with the expected argument.

mureinik avatar Oct 01 '22 13:10 mureinik