Types of Automated Unit Tests in Android Mobile App Development

Types of Automated Unit Tests in Android Mobile App Development

Live and breathe "agile development" is the slogan of the most successful business solutions companies and as a part of process, the Continuous Integration (CI) process is considered one of the main support systems. Other than the continuous build process itself, the other plug-ins that we add to the process, make it invaluable. Some of these other plug-ins are: Static Code Analysis, Automated Unit Tests, Automated UI Tests, Profiling, Beta Deployment etc. In this post, we will focus more on the ‘Automated Unit Tests’ part of it, and explain it in the context of Android app development.

Mobile Application Testing Process

Mobile Application Testing can be done either by automation or manual testing process. It's a process to build an application software by testing it for its functionality, usability, and consistency. 

Andriod Testing Process

(Note: The diagram above shows the extra steps that we’ve plugged into the Continuous Integration process.)

In this post, we’ll focus more on the ‘Automated Unit Test’ part of it, and explain it in the context of Android app development. In Android, there are two test types.

    • The tests running on our local Java Virtual Machine (JVM).
    • The tests running on our Android platform (in which we need devices or emulator).

The local unit tests and instrumented tests are just terms that help distinguish the tests that run on your local JVM from the tests that run on the Android platform.

Android Testing Suite

The real testing types that you should understand when building a complete test suite are described below:

Andriod Testing Suit.jpg

Unit Tests

Normally, in Android development, we are writing the the Java code and need JVM to run it. If a test code has no dependencies, or only has simple dependencies on Android or when you can mock the Android framework dependencies, you should run your test on a local development machine. This testing approach is efficient because it helps you avoid the overhead of loading the target app and unit test code onto a physical device or emulator every time your test is run.

In this approach, we can use small parts of our code in total isolation and test the input and outputs of our data flow. In the local unit test, With the help of mock object, we can test our codes which depend on Android framework.

1. Local Unit Tests

Unit tests that run locally on the Java Virtual Machine (JVM). Use these tests to minimize execution time when your tests have no Android framework dependencies or when you can mock the Android framework dependencies.

2. Instrumented unit tests

Unit tests that run on an Android device or emulator. These tests have access to Instrumentation information, such as the Context of the app you are testing. Use these tests when your tests have Android dependencies that mock objects cannot satisfy.

Integration Tests

For Android development, Integration test are of two types that are mentioned below:

1. Components within your app only

This type of test verifies that the target app behaves as expected when a user performs a specific action or enters a specific input in its activities. For example, it allows you to check that the target app returns the correct UI output in response to user interactions in the app’s activities. UI testing frameworks like Espresso allow you to programmatically simulate user actions and test complex intra-app user interactions.

2. Cross-app Components

This type of test verifies the correct behavior of interactions between different user apps or between user apps and system apps. For example, you might want to test that your app behaves correctly when the user performs an action in the Android Settings menu. UI testing frameworks that support cross-app interactions, such as UI Automator, allow you to create tests for such scenarios.

Free Testing Center White Paper


About the Author

Kunj Gupta is a Mobile Development Expert Kunj Gupta is a Google Certified Senior Mobile Developer at V-Soft. He works on developing apps for Android and iOS platforms, following best practices to ensure that apps run efficiently with respect to memory, CPU, battery, and network. He is also an expert in DevOps side of mobile app development, especially on automated Unit Tests and UI Tests on the Continuous Integration pipeline. Recently he has been working on applying Machine Learning in mobile apps as well.

 

Topics: Mobile Apps, Testing, Mobile Apps Testing, Mobile App Testing, Mobile Application Development, Main, Technology

Subscribe to Our Blog

Talk to a QA Expert

Recent Posts