JUnit 5 Tutorials
JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
P.S JUnit 5 requires Java 8 (or higher) at runtime
1. JUnit 5 + Maven
See this full JUnit 5 + Maven examples.
pom.xml
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
</plugins>
</build>
P.S The maven-surefire-plugin
must be at least version 2.22.0
2. JUnit 5 + Gradle
See this full JUnit 5 + Gradle examples.
gradle.build
plugins {
id 'java'
id 'eclipse' // optional, for Eclipse project
id 'idea' // optional, for IntelliJ IDEA project
}
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.5.2')
}
test {
useJUnitPlatform()
}
3. JUnit 5 Tests
- JUnit 5 @DisplayName
- JUnit 5 Assumptions
- JUnit 5 @Disabled
- JUnit 5 Conditional Test Examples
- JUnit 5 Tagging and Filtering, @Tag
- JUnit 5 Test Execution Order, @TestMethodOrder
- JUnit 5 Nested Tests
- JUnit 5 Repeated Tests
- JUnit 5 Run tests from console
- JUnit 5 Parameterized Tests
- JUnit 5 Timeouts
- JUnit 5 Expected Exceptions
- JUnit 5 Assertions
4. Third-party Assertion Libraries
- JUnit 5 + AssertJ
- JUnit 5 + Hamcrest
- JUnit 5 + Truth
5. Integration
- JUnit 5 + JUnit 4 together
- JUnit 5 + Mockito
- JUnit 5 + Spring Boot
- JUnit 5 + https://cucumber.io/
Download Source Code
$ git clone https://github.com/mkyong/junit-examples
Great! Very helpful to me…
Continue reading…
nice