Uploaded image for project: 'Apache Ozone'
  1. Apache Ozone
  2. HDDS-6729

Migrate tests to JUnit5

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Implemented
    • None
    • 2.0.0
    • test
    • None

    Description

      Use the following command to find all tests that are still using JUnit4.

      grep -rlE "org.junit.[A-Z]" . --include '*.java'

      Use the following command to find all tests that are still using JUnit3 components.

      grep -rl "junit.framework" . --include '*.java'

      Script for the class substitution:

      sed -i $1 \
      	-e 's/org.junit.After;/org.junit.jupiter.api.AfterEach;/' \
      	-e 's/@After$/@AfterEach/' \
      	-e 's/org.junit.AfterClass;/org.junit.jupiter.api.AfterAll;/' \
      	-e 's/@AfterClass$/@AfterAll/' \
      	-e 's/org.junit.Before;/org.junit.jupiter.api.BeforeEach;/' \
      	-e 's/@Before$/@BeforeEach/' \
      	-e 's/org.junit.BeforeClass;/org.junit.jupiter.api.BeforeAll;/' \
      	-e 's/@BeforeClass$/@BeforeAll/' \
      	-e 's/org.junit.Test/org.junit.jupiter.api.Test/' \
      	-e 's/org.junit.Assert/org.junit.jupiter.api.Assertions/' \
      	-e 's/junit.framework.TestCase/org.junit.jupiter.api.Assertions/' \
      	-e 's/Assert\./Assertions./'
      

      Notes for converting assertions:

      • The order of parameters for assertions with message changed, old: assertEquals(message, expected, actual), new: assertEquals(expected, actual, message). This may result in compile errors that need to be fixed. Also, assertEquals(String, String, String) would successfully compile, but fail during test.
      • The name Assertions is a bit longer and conversion might result in lines over 80 chars, causing checkstyle failure.

      See also: https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4

      Subtasks that remove the last JUnit4 usage in the submodule should add <allow.junit4>false</allow.junit4> to pom.xml, to prevent new JUnit4 tests being added in the future.

      Attachments

        Issue Links

          There are no Sub-Tasks for this issue.

          Activity

            People

              ckj Kaijie Chen
              ckj Kaijie Chen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: