- 添加依赖 - 选对版本
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
- 添加注解
@RunWith(SpringRunner.class)
@SpringBootTest //(classes = application类.class)
方法上添加注解
@Test
- test result 报错 :Runner org.junit.internal.runners.ErrorReportingRunner
把
import org.junit.jupiter.api.Test;
替换为
import org.junit.Test;
- WEB项目需要加入注解
@WebAppConfiguration
- 引入配置文件
@TestPropertySource("classpath:appConfig.properties")