导入maven包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
测试类上面加上注解
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ServiceApplication.class)
这是1.5以上版本的
1.4的可以用
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ServiceApplication.class)