spring boot 單元測試錯誤
阿新 • • 發佈:2019-01-22
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 問題原因是單元測試類需要和主程式類在相同包下