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 问题原因是单元测试类需要和主程序类在相同包下