spring boot 单元测试错误

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

之前一直都不怎么习惯使用单元测试,最近在学习spring boot 试了一下,记录一下遇到的问题

@RunWith(SpringRunner.class)
@SpringBootTest
public class PesionTest {

    @Autowired
    ApplicationContext app;

    @Test
    public void getService() {
        System.out.println(app.containsBean("helloService"));
    }
}

遇到了java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test 问题原因是单元测试类需要和主程序类在相同包下
这里写图片描述

posted @ 2018-05-24 14:38  大于吃小于  阅读(203)  评论(0编辑  收藏  举报