使用idea基于springBoot的项目进行单元测试时,出现异常,一般就两个原因。
Test ignored.
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
1、没写启动类
这个就不用多说,肯定能一眼看到
2、包名写错,两个包名不相同,springboot扫描不到。
包名必须相同,这样Springboot才能扫描到。
3、你就是不想把包名整一样,好吧!你牛!!也行那就按照错误提示来
@SpringBootTest(classes = {ProductApplication.class})
public class ProductApplicationTest {
@Autowired
MyanmarService myanmarService;
@Test
public void test(){
myanmarService.getFlowPackage("friendship");
}
}