Android单元测试的最佳做法? [英] Best practices for Android Unit Testing?

查看:71
本文介绍了Android单元测试的最佳做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发移动android应用. Android单元测试中最常用的库/框架是什么?我觉得大多数业务逻辑,数据库测试,Web服务测试都可以使用JUnit完成.

但是,测试UI,UI工作流程等的最佳方法是什么?例如,我们如何测试Android应用是否成功启动网络浏览器?还是我们如何确认按钮,某些东西是否被成功按下?还是图像加载成功?

解决方案

我使用 JUnit 进行单元测试和 Robolectric 用于仪器测试.

本文向您展示了Robolectric的Hello World示例

最近,我一直在研究使用 Arquillian Droidium 在Android中进行集成测试. /p>

如果您要测试一些使用REST API的代码,则可以使用 WireMock 对其进行模拟.使用此库,您可以通过代码模拟REST API,甚至可以在自己的计算机中部署模拟HTTP服务器并设置自己的模拟映射.

对于REST API模拟,我还建议您使用 Mockable.io .

I am developing a mobile android app. What are the most common libraries/frameworks used for Android unit testing? I feel that most of the business logic, database testing, Web services testing can all be done using JUnit.

However, what's the best approach for testing UI, the UI workflow, etc? For example, how can we test if the Android app launches a web browser successfully? Or how can we confirm if buttons, certain things are pressed successfully? Or if images are loaded successfully?

解决方案

I use JUnit for unit testing and Robolectric for instrumentation tests.

This article shows you a Hello World example with Robolectric

In recent times, I have been researching about integration testing in Android using Arquillian Droidium.

If you want to test some code that consumes a REST API, you can mock it with WireMock. With this library, you can mock REST APIs by code or even deploy a mock HTTP server in your own machine and set up your own mocked mappings.

For REST API mocks, I also recommend you to use Mockable.io.

这篇关于Android单元测试的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆