android dev官方网站上, 对于测试一个android库, 有如下2个建议.
1. You can set up a test project that instruments an application project that depends on the library project. You can then add tests to the project for library-specific features.
(需要有一个app工程, 依赖了这个android 库工程, 那么你写一个android工程,测试这个app. 这个方法, 和传统的测试app的方法一致.)
2. You can set up a set up a standard application project that depends on the library and put the instrumentation in that project. This lets you create a self-contained project that contains both the tests/instrumentations and the code to test.
(这个是说, 你直接测试这个android 库工程. 你需要创建一个标准的android app工程依赖于这个android库, 然后进行instrumentation. 这相当于说, 你的这个测试工程, 是一个标准app工程+测试工程的集合体). 反过来说, 我们认为是一个测试工程, 里面加上了标准android app的定义. 那么就相当于, 自己测自己. 但实际因为依赖了三方的android库, 所以, 实际测的是android库代码.
有点拗口了. 我们来看个实际的例子吧. 更多…