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

猜你喜欢

转载自xuantan.iteye.com/blog/1870484