[
https://issues.apache.org/jira/browse/HDDS-6729?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Attila Doroszlai updated HDDS-6729:
-----------------------------------
Description:
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
was:
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}
> 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
>
> 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
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]