I tried migrating an existing JUnit 4 project to take advantage of JUnit 5 features.
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>
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 |
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.
Recommended Posts