使用SpringBootTest测试的时候报错:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
Test1类
@RunWith(SpringRunner.class)
@SpringBootTest
public class Test1 {
@Test
public void getLines() throws IOException, InterruptedException{
Cal cal = new CalImpl();
System.out.println(cal.add(1, 2));
}
}
原因是我建springboot项目的时候漏写了一个注解:@SpringBootApplication,加上即可
@ContextConfiguration
@EnableAutoConfiguration
@ComponentScan
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
结果: