Pet*_*old 5 junit android unit-testing
根据此SDK指南,可以通过创建标准应用程序项目,引用Library项目然后检测应用程序以进行单元测试来实现对项目的单元测试.
但是,当我这样做并启动测试应用程序时,我得到了消息
没有测试跑步者'JUnit 3'的测试结果.
我正在使用Eclipse和Android ADT插件,所有最新版本.
注意:项目编译得很好.测试项目也可以很好地安装到模拟器.但是在控制台中我可以看到它正在寻找<library>.apk,当然这不存在,因为我将它作为一个库编译到测试项目中.
有人这个上班吗?如果是这样,这里的诡计是什么?
更新:在发现并修复问题(实际上包括测试类(!))之后,测试运行器现在可以找到所有测试.但是,所有测试都失败,但有以下例外:
java.lang.NoClassDefFoundError:<nameOfClassInLibraryProject>
nameOfClassInLibraryProject是库项目中定义的类.这些类应该编译到测试项目中,事实上,一切都编译得很好.但是在运行测试项目时,运行时似乎找不到库类.
在Eclipse中大量摆弄和浪费时间后,我设法让Android库项目工作.
根据图书馆工作项目的文章:
相反,您必须通过从依赖应用程序的构建路径引用库,然后构建该应用程序来间接编译库.
The problem was that I interpreted this to mean that the library project should be added to the Projects tab in Java Build Path. Doing this makes the test project compile since the library code is obviously available to the compiler. But since the library is not compiled into a .jar or .apk in itself, the library classes are never deployed to the device.
The solution is to not add the library project to Projects, rather on the Source tab, add the library /src folder using the Link Source... button. And yes, it is the library src folder, not the library project root, that must be linked into the test project.
| 归档时间: |
|
| 查看次数: |
2179 次 |
| 最近记录: |