`
zhangym124
  • 浏览: 339418 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

robolectric + eclipse NoClassDefFoundError (can run tests from Maven command)

阅读更多

转载请注明出处:http://xuantan.iteye.com/blog/1870484

 

使用Robolectric作为Android单元测试框架时,碰到如下问题:

场景:Robolectric + Maven + Eclipse

在命令行下:mvn clean test,测试用例执行

但在Eclipse中,Run As > JUnit Test 时却报错:NoClassDefFoundError:R.java

 

原因为:没有将android.jar 加入测试环境的classpath中.

 

解决方法:

Right-click -> Run As -> Run Configurations
Tab: Classpath -> User Entries -> Add External JARs ...

找到你的android.jar并选择.

 

重新运行测试用例,成功!

 

 

注:如果在Eclipse中运行测试用例,遇到报测试类找不到的情况,可以在命令行下mvn clean test,然后回到Eclipse,刷新工程即可.

 

 

转载请注明出处:http://xuantan.iteye.com/blog/1870484

1
5
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics