You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Wei-Chiu Chuang (Jira)" <ji...@apache.org> on 2025/03/27 22:38:00 UTC

[jira] [Updated] (HDDS-6729) Migrate tests to JUnit5

     [ https://issues.apache.org/jira/browse/HDDS-6729?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wei-Chiu Chuang updated HDDS-6729:
----------------------------------
    Release Note: Unit tests have completely migrated to JUnit 5

> Migrate tests to JUnit5
> -----------------------
>
>                 Key: HDDS-6729
>                 URL: https://issues.apache.org/jira/browse/HDDS-6729
>             Project: Apache Ozone
>          Issue Type: Improvement
>          Components: test
>            Reporter: Kaijie Chen
>            Assignee: Kaijie Chen
>            Priority: Minor
>             Fix For: 2.0.0
>
>
> Use the following command to find all tests that are still using JUnit4.
> {code:java}
> grep -rlE "org.junit.[A-Z]" . --include '*.java'{code}
> Use the following command to find all tests that are still using JUnit3 components.
> {code:java}
> grep -rl "junit.framework" . --include '*.java'{code}
> Script for the class substitution:
> {code:bash}
> 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./'
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org