引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency>
在测试类上加注解
@RunWith(SpringRunner.class) //替代junit原生的运行器 @SpringBootTest(classes = RabbitmqApplication.class)
在测试方法上加
@Test
传统方式
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:spring/springmvc.xml")