测试 Android 库
按照它在 Eclipse 上进行 Android 开发的方式,您可以轻松地:
- 创建一个库项目,然后不会生成 apk,而是生成一个 jar,该 jar 将作为依赖项添加到将使用该库的应用程序
- 创建一个 android 项目,而不是生成一个 jar。使用 Instrumentation 测试用例等轻松为其创建一个测试项目。
这非常有效。但是如何为 Android 库提供单元和功能测试呢?
一旦我通过 eclipse 将我的库项目转换为库,它就不再可测试,因为没有生成 apk,也没有在设备上安装 apk 来由测试应用程序检测。
更重要的是,如果我的库需要一些权限,使用该库的应用程序可以将权限添加到其清单中,但测试应用程序不能这样做!测试框架使用被测应用程序(而不是测试应用程序)声明的权限来检测测试的应用程序。
一个明显的答案不是对库本身进行单元测试,而是使用该库测试示例应用程序,但我们距离单元测试还很远......
提前感谢各位!
有关此问题的更详细信息,请参阅此处< /a>.
In the way it works on Eclipse for Android development, yuo can easily :
- create a library project, and then no apk will be generated but rather a jar that will be added as dependency to apps that will use the library
- create an android project and rather easily create a test project for it, using Instrumentation test cases, etc..
This works pretty well. But how do you provide unit and functional tests for an android librairy ?
As soon as I turn my library-project into a library through eclipse then, it's not testable any more as no apk is generated, no apk is installed on the device to be instrumented by the test app.
And more over, if my lib needs some permissions, an app using the lib can add the permissions to its manifest, but a testing app can't do that ! The testing framework instruments the tested app using the permission declared by the app under test, not the testing app.
An obvious answer would be not to unit test the library itself, but to test a sample app using the library but we are far from unit tests...
Thanks in advance, folks !
A more detailled aspect of this problem can be found here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您最后建议的解决方案是我们一直在使用的解决方案。我们创建一个库和一个仅加载该库的简单程序。早期,我们只是确保一切都按预期构建和工作,但随后您可以将单元测试添加到简单的非库程序中。
抱歉,根据我们的经验,这是最好的方法。
The solution you suggest at the end is the one that we've been using. We create a library and a simple program that just loads up the library. Early on we just ensure that everything builds and works as expected, but you can then add unit tests to the simple, non-library program.
Sorry, in our experience, that is the best way.