2019独角兽企业重金招聘Python工程师标准>>>
如果是使用spring-boot 1.4以下的版本
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = 启动类.class)
public class ApplicationTest {//代码省略
}
使用@SpringApplicationConfiguration注解
如果spring-boot是1.4以上的版本
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = 启动类.class)
public class ApplicationTest {//代码省略
}
使用@SpringBootTest注解
PS:本人测试的时候,因为是1.4以上的版本,使用@SpringApplicationConfiguration注解一直报错,跑注解源码一看,发现下面一段话:
@deprecated as of 1.4 in favor of {@link SpringBootTest} or direct use of {@link SpringBootContextLoader}
弃用:1.4版本支持 @SpringBootTest注解,或者直接使用 @SpringBootContextLoader注解,
改过来,使用@SpringBootTest就能正常跑了!