Testing is Part of Android Development.

2 minute read

Test is part of your development

Testing your app is part of the development process. Usually, we do testing manually and automate it. Manual testing does by a person, who creates a test case and validates the features. Automate test, this is part of the developer testing their code following the requirement of features. By including tests, you can ensure that your code works and that later changes to the code won’t break it. You can get early failure before the app ships to the user. The test will help developers to understand what the code does. You can also see what the code should not do. The test itself can be sure this form of documentation is up-to-date.

The Test Pyramid

Mike Chon came up with this concept in his book Succeeding with Agile. The visual will be telling you about the different layers of testing. Also how much testing is to do on each layer?

PlantUML Extension

From the diagram, you should have lots of small unit tests, some integration, and fewer UI tests.

1. Unit Tests

Unit test is quickest, easiest and chepest to run. Unit test is way of testing piece of code that can be loggically isolated in a system. They are independent of the Android framework. We focus test isolate one class and assume the dependecies are consider working correctly. When test the class usually we mocked the dependecies.

Example :

MVVM Android Achitecture

The unit test will focus on one class like view model, and all dependencies will be mocked/stubbed, such as the Repository Unit test on android has some common libraries for testing:

Library for Mocking / Stubing

2. Integeration Tests

Integration tests are testing how things work together. Integration tests are slower than unit tests, and more expensive also. In Android development, the test usually checks how the code interacts with other parts like the Android framework or external libraries.

If following the MVVM android architecture above. Integration tests can do testing from a view model and interaction with a Network or Database. Must remember we don’t test with real networks or databases. All things will be mocked or stubbed. Integration tests can run on a JVM machine or Device Android. Depends on your need or the library you use.

Some common libraries for integration testing.

If using Retrofit and OkHttp Client you can use mockwebserver for mock responses.

3. UI Test

UI Test is the most expensive and slowest. Others can call as an end-to-end test. Because the test will be a test application from a user perspective. For dependencies will be using real such as, hitting API to the backend, saving data to the local database or etc. Android has espresso for the native library. Otherwise, you can use Appium this is for UI automation support for android and iOS.

Wrap Up

  • Implementation tests on your project can make you more confident to release to users.
  • Have 3 different types of tests, and you can priorities on the Unit test first. Because that is the fastest you can do it.
  • Always remember The test Pyramid before you decide on the strategy for testing.