Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to JUnit Jupiter #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mureinik
Copy link

@mureinik mureinik commented Oct 1, 2022

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.

This patch 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 patch includes:
1. pom.xml
  a. The junit:junit:4.13.1 dependency was replaced with the modern
     org.junit.jupiter:junit-jupiter:5.9.1 dependency
  b. An implicit 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.
  c. maven-dependency-plugin's excludeArtifactIds configuration was
     updated to exclude junit-jupiter instead of junit

2. Annotations
  a. 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.c below
  b. org.junit.jupiter.api.BeforeEach was used as a drop-in
     replacement for org.junit.Before.
  c. org.junit.jupiter.api.BeforeAll was used as a drop-in
     replacement for org.junit.BeforeClass.
  d. org.junit.jupiter.api.AfterEach was used as a drop-in
     replacement for org.junit.After.
  e. org.junit.jupiter.api.AfterAll was used as a drop-in
     replacement for org.junit.AfterClass.
  f. In the cases where multiple annotations were replaced in the same
     class, imports were reorganized to keep their alphabetical order.

3. Assertions
  a. 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.
  b. 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.
  c. org.junit.jupiter.api.Assertions' assertThrows was used to test
     expected exceptions being thrown where org.junit.Test was used
     with the expected argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant