Android 测试驱动开发

Android Test Driven Development(Android 测试驱动开发)

本文介绍了Android 测试驱动开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在制作 Android 应用程序方面拥有丰富的经验.对于我的新项目,我们决定进行测试驱动开发 (TDD).我一直在使用 Robotium 进行用户场景测试,它运行良好,看起来也很简单.

I have considerable experience in making Android applications. For my new project, we have decided to do Test Driven Development (TDD). I have been getting my hands wet on Robotium for User Scenario Testing, and it works fine and looks easy too.

对于单元测试,我尝试使用 (MockContext Android Class) 模拟 Context,但我无法这样做.我浏览了这个博客 http://sites.google.com/site/androiddevtesting/ 和通过这个 http://sdudzin.blogspot.com/2011/01/easy-unit-testing-for-android.html ,这表明 Android 应用程序中的模拟仍然非常有限和困难,并建议使用 PowerMock、jMockit、JeasyTest 或 Roboelectric(结合Mockito 和 Maven)甚至 RoboGuice.

For unit testing, I tried to mock Context using (MockContext Android Class) but I am unable to do so. I went through this blog http://sites.google.com/site/androiddevtesting/ and through this http://sdudzin.blogspot.com/2011/01/easy-unit-testing-for-android.html , which suggests that mocking in Android apps is still very limited and hard, and have suggested to use PowerMock, jMockit, JeasyTest, or Roboelectric (in combination with Mockito and Maven) and even RoboGuice.

我想就您认为哪种单元测试框架最适合测试 Android 应用程序从你们那里得到任何建议.(特别是测试 Android 类,可能会提供模拟上下文和其他模拟功能,以便我可以使我的测试用例尽可能独立).任何建议或指示都会有所帮助.谢谢

I would like to get any suggestions from you guys on which unit testing framework in your opinion is the best for testing Android applications. (particularly testing Android classes, possibly giving mock Contexts and other mocking features so that I can make my test cases as independent as possible). Any suggestions or pointers would be helpful . Thanks

推荐答案

对于离线测试,请查看 Robolectric

For off-device testing, look at Robolectric

对于设备上的测试,请查看 波拉契奥

For on-device testing, look at Borachio

底线:要做好仍然非常非常困难.情况正在好转(今天的情况比 6 个月前要好得多),但 Android 无疑是我编写过的程序中对测试最不利的环境.

Bottom line: it's still very, very difficult to do well. Things are improving (the situation is dramatically better today than it was 6 months ago) but Android is comfortably the most test-hostile environment I've ever written programs for.

这篇关于Android 测试驱动开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android 测试驱动开发

基础教程推荐