Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating specific tests from JUnit 4 to JUnit 5 in IntelliJ

I am trying to migrate test files from Junit 4 to Junit 5 using IntelliJ refactor code -> migrate -> junit 4 to junit 5.

But it only run import optimization and show all unit tests in the project and ask yes or no on refactoring and nothing happens when I chose do refactor.

any one know on another migration tool / plug in or a way to make the migration work ?

like image 548
Ran Koretzki Avatar asked Oct 23 '17 06:10

Ran Koretzki


People also ask

How do I migrate from JUnit 4 to JUnit 5 in IntelliJ?

Use Find Action with ⌘⇧A (macOS), or Ctrl+Shift+A (Windows/Linux), and type Migrate, to see migration options for the code. IntelliJ IDEA offers the option to migrate the code from JUnit 4 to 5. This migration is similar to what we did with the individual test class, but for all test classes.

Can JUnit 4 and 5 be used together?

You can migrate tests written in JUnit 4 to JUnit 5 with minimal effort. Here are the steps to perform the migration: The JUnit Vintage engine in JUnit 5 helps in running existing test cases written in JUnit 4 (or JUnit 3) utilizing the JUnit Platform.

Is it possible to use JUnit 4 and JUnit 5 tests in the same test project or suite )?

Running tests with IntelliJ IDEA Vintage engine discovers and runs the JUnit 4 tests. Jupiter runs its own discovery and execution phases where it discovers and executes JUnit 5 tests only. So not that you can only run JUnit 4 and JUnit 5 tests in the same project, you can also do that in the same test class.


2 Answers

Jeanne Boyarsky created a tool to convert JUnit 4 based tests to JUnit Jupiter.

You can find it in her GitHub account: https://github.com/boyarsky/convert-junit4-to-junit5

like image 185
Sam Brannen Avatar answered Oct 13 '22 03:10

Sam Brannen


It seems that converting test from JUnit 4 to JUnit 5 in IntelliJ 2017.3 is not complete. As suggested by Sam Brannen there is a small application on Github called convert-junit4-to-junit5 that can do the job.

Just clone the Github repo and build the software using Maven mvn clean package. Then run the the application using

java -jar \
     <path-to-your-cloned-repo>/convert-junit4-to-junit5/target/convert-junit4-to-to-junit5-0.0.1-SNAPSHOT.jar \
     <path to where your JUnit 4 tests are located>

For further instruction please read the projects documentation.

like image 27
saw303 Avatar answered Oct 13 '22 02:10

saw303