Skip to content

Latest commit

 

History

History
85 lines (73 loc) · 1.8 KB

File metadata and controls

85 lines (73 loc) · 1.8 KB

JUnit 4 / 5 for Spring Boot

According to next video by John Thompson

Useful Baeldung article

JUnit 4

import org.junit.Test;

@RunWith(SpringRunner.class)
@SpringBootTest
public class AppTest {
    @Test
    public void contextLoads() {
    }
}
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

JUnit 5

import org.junit.jupiter.api.Test;

@ExtendWith(SpringExtension.class)
@SpringBootTest
public class AppTest {
    @Test
    public void contextLoads() {
    }
}
<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
      <exclusion>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>
<build>
  <plugins>
    <plugin>
      <artifactId>maven-surefire-provider</artifactId>
      <version>2.22.0</version>
      <dependencies>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-surefire-provider</artifactId>
        <version>${junit-platform.version}</version>
      </dependencies>
    </plugin>
  </plugins>
</build>