Android UI Automation: Part 2, Making It Easy

In Part 1 we introduced the targeted and hermetic UI test approach that helped Slack Android engineers write hundreds of stable UI tests. However, as our UI test suite expanded, we detected a problem. When asked how easy it was to write tests on a scale from 1 (terrible) to 4 (excellent), developers ranked it…

Kevin Lai
11 min readadvanced
--
View Original

Overview

This article discusses enhancements made to the Android UI automation testing framework at Slack, focusing on improving the developer experience and reducing complexity in test setup. It introduces the PowerPack pattern, which simplifies the initialization of test data, and highlights the positive impact on the ease of writing tests.

What You'll Learn

1

How to implement the Robot pattern for UI tests in Android

2

Why using the PowerPack pattern simplifies test data setup

3

How to configure a test workspace using JSON

Prerequisites & Requirements

  • Understanding of UI testing concepts and frameworks
  • Familiarity with mocking frameworks like Mockito(optional)

Key Questions Answered

How does the PowerPack pattern improve UI test setup?
The PowerPack pattern encapsulates the complexity of initializing test data, allowing developers to focus on the test models rather than the underlying components. This abstraction reduces repetitive mocking and simplifies the setup process, leading to clearer and more maintainable tests.
What challenges do developers face when writing UI tests?
Developers often struggle with the complexity of setting up the necessary state for UI tests, requiring extensive mocking of dependencies. This complexity can lead to frustration and inefficiencies, as each developer may have to replicate similar setups for their tests.
What improvements were observed in developer experience after implementing PowerPack?
After implementing the PowerPack, the ease of testing score in the Developer Experience survey improved from 2.5 to 2.92. Developers noted significant enhancements in the process of writing tests, indicating a positive shift in their workflow and satisfaction.

Key Statistics & Figures

Ease of Testing Score
2.92
This score reflects the improvement in developer experience after implementing the PowerPack pattern.

Technologies & Tools

Tools
Mockito
Used for mocking dependencies in UI tests.
Tools
Gson
Used for parsing JSON configuration files into model objects.

Key Actionable Insights

1
Adopt the Robot pattern in your UI tests to enhance readability and reduce code duplication.
By separating the interaction logic from the test logic, you can create more maintainable tests that are easier to understand and modify. This approach is particularly beneficial in large codebases.
2
Utilize the PowerPack pattern to streamline your test data setup.
This pattern allows you to encapsulate complex mocking logic into reusable components, significantly reducing the time spent on test preparation and improving overall testing efficiency.
3
Consider using JSON configuration files for setting up test environments.
By externalizing configuration data, you can simplify the initialization process and make it easier to manage different test scenarios without hardcoding values in your test code.

Common Pitfalls

1
Overcomplicating test setups with repetitive mocking code.
This often occurs when developers do not abstract common setup logic, leading to duplicated efforts and increased maintenance overhead. To avoid this, utilize patterns like PowerPack to encapsulate and reuse setup logic.

Related Concepts

UI Testing Frameworks
Mocking Techniques
Test-driven Development