I have a JUnit 4 test class in Eclipse Ganymede that has the following annotations :
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/applicationContext.xml"})
public class TestSybaseDao extends TestCase {
This annotation gives compilation error "Type mismatch: cannot convert from Class<SpringJUnit4ClassRunner> to Class<? extends Runner>
在写单元测试的时候,明明包导进去了但是鼠标放到调用类还会出现这个错误。
出现这种情况一般有2个原因:
1.可能刚加进去的包为加载到,需要到重构配置窗口中重新加载下所有包,一般eclipse自带的是junit4.4版本的。
2.第二种原因是spring不支持junit4.5一下的版本。所以只需要把junit4.4或者更低版本升级到更高就ok了。
本文探讨了在Eclipse Ganymede中使用JUnit4与Spring集成进行单元测试时遇到的类型转换错误。主要分析了两种可能的原因:一是依赖包未加载成功;二是Spring不支持JUnit的旧版本,并给出了相应的解决方案。

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



