[JAVA] Migrate from JUnit 4 to JUnit 5

I tried migrating an existing JUnit 4 project to take advantage of JUnit 5 features.

Migration procedure

(1) Add a dependency

Add the following three dependencies.

pom.xml description example (latest version as of November 28, 2018)

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.3.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.3.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.3.2</version>
    <scope>test</scope>
</dependency>
(2) Update the test method

You can use junit-vintage-engine to run JUnit 3 and JUnit 4 tests on JUnit 5, but you can also update anything that can be converted by simple annotation replacement.

JUnit 4 (org.junit.*) JUnit 5 (org.junit.jupiter.api.*)
Test Test ※
Ignore Disabled
Before BeforeEach
After AfterEach
BeforeClass BeforeAll
AfterClass AfterAll

Run JUnit 5 in Eclipse

You can run JUnit 5 with Eclipse 4.7.3 (Oxygen) or above. To run it, right-click on the class (method) you want to test → Run → JUnit Test.

reference

Recommended Posts

Migrate from JUnit 4 to JUnit 5
How to migrate from JUnit4 to JUnit5
Migrate from on-premise Pukiwiki to esa.io \ (⁰⊖⁰) /
Migrate from Java to Server Side Kotlin + Spring-boot
From Java to Ruby !!
Migrate from Transport Client to Rest High Level Client
How to use JUnit 5
[Swift, ARKit] Migrate from deprecated hitTest to raycastQuery
Moved from iBATIS to MyBatis3
Try Spring Boot from 0 to 100.
Migration from Cobol to JAVA
Switch from slim3-gen to slim3-gen-jsr269
Moving from AWS to PaizaCloud
How to use JUnit (beginner)
New features from Java7 to Java8
Migrating from vargrant to docker
Migrate GitBucket database to postgreSQL
Introduction to JUnit (study memo)
Connect from Java to PostgreSQL
Convert from ○ months to ○ years ○ months
How to write Junit 5 organized
Rewriting from applet to application
Change from SQLite3 to PostgreSQL
From Ineffective Java to Effective Java
[Creating] How to use JUnit
How to push from Tarminal to GitHub
protocol buffeer migration from 2.x to 3.x
How to run JUnit in Eclipse
[Note] Download from S3, upload to S3
Stop resending from client to server
Ubuntu Desktop upgrade from 18.0.4 (?) To 20.04.1 (focal)
Migrate Docker image to another server
Upgrade from MYSQL5.7 to 8.0 on CentOS 6.7
From introduction to use of ActiveHash
Switch from JSP + JSTL to Thymeleaf
Java to be involved from today
From Java to VB.NET-Writing Contrast Memo-
Introduction to Ruby (from other languages)
Java, interface to start from beginner
Introducing Java tips GreenMail to Junit5
Change DB from SQLite to MySQL
Notes on migrating from CircleCI 1.0 to 2.0
Addicted to project imports from GitHub
junit
Upgrade spring boot from 1.5 series to 2.0 series
We aim to update daily from 2021
From introduction to usage of byebug
Switch from Eclipse to VS Code
The road from JavaScript to Java
Memorandum Poem (updated from time to time)
[Java] Conversion from array to List
Update MySQL from 5.7 to 8.0 with Docker
to_ ○
How to change from HTML to Haml
From pulling docker-image of rails to launching
Migrate Dockerhub images to Github Container Registry
Investigate the replacement from Docker to Podman.
[Kotlin] 3 ways to get Class from KClass
Add foreign key to column with migrate
[Rails] How to convert from erb to haml
How to filter JUnit Test in Gradle