本篇主要记录在学习android单元测试的过程中遇到的一些问题和解决方法,以后遇到的时候能够随时翻阅。
Junit 出现的问题Empty test suite
运行单元测试出现Class not found: "package.ExampleUnitTest"Empty test suite.错误
项目运行了但实际上并没有建立单元测试,即使配置了Junit,此时,首先Build->Make Project然后再运行测试就可以了;参考:
It seems the Run action doesn’t actually build unit tests even though you have a JUnit configuration selected. First running “Make project” and then “Run” will work fine.
更新
使用 JUnit 4.12 报错 NoClassDefFoundError: org/hamcrest/SelfDescribing
缺少 hamcrest 包。
junit.jar: Includes the Hamcrest classes. The simple all-in-one solution to get started quickly.Starting with version 4.11, Hamcrest is no longer included in this jar.
JUint 需要依赖 hamcret 包,但是4.11后没有这个包了,需要手动添加。