/Write better tests with the new testing guidance

Write better tests with the new testing guidance

Posted by Jose Alcérreca, Android Developer Relations Engineer

Blue illustration with Android phone 

As apps increase in functionality and complexity, manually testing them to verify behavior becomes tedious, expensive, or impossible. Modern apps, even simple ones, require you to verify an ever-growing list of test points such as UI flows, localization, or database migrations. Having a QA team whose job is to manually verify that the app works is an option, but fixing bugs at that stage is expensive. The sooner you fix a problem in the development process the better.

Automating tests is the best approach to catching bugs early. Automated testing (from now on, testing) is a broad domain and Android offers many tools and libraries that can overlap. For this reason, beginners often find testing challenging.

In response to this feedback, and to accommodate for Compose and new architecture guidelines, we revamped two testing sections on d.android.com:


Firstly, there is the new Testing training, which includes the fundamentals of testing in Android with two new articles: What to test, an opinionated guide for beginners, and a detailed guide on Test doubles.

Faking dependencies in unit tests

Faking dependencies in unit tests

After providing an overview of the theory, the guide focuses on practical examples of the two main types of tests.

Local tests that run on a workstation and are typically unit tests.

Instrumented tests that run on a device. This section includes an introduction to UI tests and the AndroidX Test libraries.

Faking dependencies in UI tests

Faking dependencies in UI tests

Tools Documentation

Secondly, we updated the Testing section of the Tools documentation that focuses on all the tools that help you create and run tests, from Android Studio to testing from the command line.

The Unified Gradle test runner.

The Unified Gradle test runner.

We included an article that describes Advanced test setup features such as working with different variants, the instrumentation manifest options, or the Android Gradle Plugin settings.

These two new sections should give you a general notion of how and where to test your Android app. To learn more about testing specific features and libraries, you should check out their respective documentation pages. For example: Testing Kotlin flows, Test Navigation, or the Hilt testing guide.

Sadly, machines can’t automatically verify the correctness of our documentation, so if you find errors or have suggestions, please file a bug on our documentation issue tracker.

Read more: android-developers.googleblog.com

Original Source

I am a philosopher and my interest is in the many diversified cultures of mankind. In my writing I try to understand what insights mankind needs to learn in order to control climate change, to create a new paradigm for global decision making and to benefit from the opportunities of the Digital Age. I hope this site will offer insights to share. Thanks and have a very good day on our common and only planet!