Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for Android Unit Testing?

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?

like image 335
code Avatar asked Nov 18 '15 16:11

code


People also ask

What should I test in unit tests Android?

Unit tests or small tests only verify a very small portion of the app, such as a method or class. End-to-end tests or big tests verify larger parts of the app at the same time, such as a whole screen or user flow. Medium tests are in between and check the integration between two or more units.


1 Answers

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.

like image 52
Héctor Avatar answered Sep 23 '22 11:09

Héctor