Springboot单元测试一定要加@RunWith!!!
要加入
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
这两个包
才会有
@RunWith(SpringRunner.class)
@SpringBootTest
这两个注解
如果不加@RunWith注解会出现dao层无法注入
另外单元测试报的错找不到问题关键的话,直接启动项目,看它报的错,说不定更有用