案发现场
@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));
}
}
解决方案
保证测试类所在的包被main入口扫描到
比如:@ComponentScan扫描的包是com.itplh, 而单元测试的类所在包为org.itplh, 这样就会导致报错
本文探讨了在SpringBoot项目中正确配置单元测试的方法,解决因@ComponentScan导致的测试类未被扫描的问题,确保测试环境的正常运行。
2157

被折叠的 条评论
为什么被折叠?



