公司SpringBoot项目中,进行单元测试中
运行测试代码时,报错
警告: Runner org.junit.internal.runners.ErrorReportingRunner (used on class cn.midea.sdmmastest.util.connectUtilTest) does not support filtering and will therefore be run completely.
完整报错如下:
五月 11, 2021 11:14:45 上午 org.junit.vintage.engine.descriptor.RunnerTestDescriptor warnAboutUnfilterableRunner
警告: Runner org.junit.internal.runners.ErrorReportingRunner (used on class cn.midea.sdmmastest.util.connectUtilTest) does not support filtering and will therefore be run completely.
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:137)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
包导错了,在@Test有两个包,一个是org.junit.jupiter.api.Test,另一个是org.junit.Test,而测试需要的Junit是org.junit.Test
将 import org.junit.jupiter.api.Test;
替换为 import org.junit.Test;