[Spring][Junit Test] Class<SpringJUnit4ClassRunner> cannot be resolved to a type

在手动编写Junit测试时, 提示 "Class<SpringJUnit4ClassRunner> cannot be resolved to a type"

如图:



网上找过很多方法多没有解决我的问题.

最后通过对比正常的junit测试用例, 发现是因为没有import SpringJUnit4ClassRunner.

只需在import下面的包即可.

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


感觉eclipse比较傻, 不会提示让你导入这个包.

需要指出的是, 此问题和spring-test版本无关, 5.0.2也是OK的.(有网上的帖子说要用4.1.6版本的) 

            <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.0.2.RELEASE</version>
            <scope>test</scope>
        </dependency>


猜你喜欢

转载自blog.csdn.net/hui85206/article/details/80209275