android-end-to-end-tests
title: End-to-End Testing Guide sidebar_label: E2E Testing
The main objective of E2E testing is to validate the flow of data and interactions between various components of the Android app, from user input to backend services and back. By doing so, it helps in identifying any integration issues, data inconsistencies, or other potential bugs that might not be caught during unit or integration testing.
Environment Setup
Before running end-to-end (E2E) tests, it is essential to define specific environment variables to ensure the correct configuration of backend services and authentication. These environment variables can be set up in your test environment to ensure smooth interaction between your app and the backend services.
Defining Environment Variables:
To configure the environment for E2E testing, follow these instructions :
1. Open the terminal and edit your ~/.zshrc file using a text editor:
nano ~/.zshrc
- Add the following lines at the end of the file to define the environment variables for E2E testing:
export CORE_URL="https://api.uat.core.ladbrokes.cloud"
export ADMIN_CLIENT_SECRET="f0a8f9a2-0a47-4f16-9fb7-fa83f0c51eac"
export ADMIN_CLIENT_ID="load-tester"
export ADMIN_AUTH="https://authentication.uat.aws.neds.com"
export ADMIN_AUTH_REALM="auth/realms/Neds%20International%20Pty%20Ltd"
Save the file by pressing CTRL + O, then press Enter. Exit the editor with CTRL + X.
Apply the changes by running the following command in the terminal:
source ~/.zshrc
- Our CI pipeline runs on a Pixel 4a with API 34. To ensure consistency with this environment, it's recommended to use the same setup.
To create an end-to-end test using the BaseEndToEndTest class, follow these steps:
Create a Class Inheriting BaseEndToEndTest:
Start by creating a new test class that extends BaseEndToEndTest. This gives your test class access to all the setup and utility functions provided by the base class.
Use/Create a Helper Class:
Utilize helper classes like PageHelper to simplify interactions with the UI components. These helpers abstract away complex UI operations, making your test code more readable and maintainable.
Write the Test:
Write the actual test methods within your class, utilizing the provided helpers and the setup environment to interact with the app's UI and verify expected behaviors.
BaseEndToEndTest
Overview
BaseEndToEndTest is an abstract base class designed to simplify end-to-end (E2E) testing in Android by handling dependency injection, permissions, and essential test rules.
Key Components
React Page Load: Ensures Espresso waits for React pages to fully load before interacting. WebView Load: Waits for WebView components within the app to finish loading. App Startup: Prevents tests from starting until the app is fully initialized. Network Requests: Waits for all network requests to complete before proceeding with tests. Thread Dispatchers: Ensures that all jobs on the main, IO, and default threads are completed before interacting with the UI.
By managing these idling resources, BaseEndToEndTest helps prevent flaky tests and ensures that interactions occur only when the app is ready. This logic is stored in entainHiltRule.
Usage :
@HiltAndroidTest
class SignUpTest : BaseEndToEndTest() {
Running
Currently, only UAT is functional (some tests may require adjustments to backend data linked to the test account).
Feature flags are specified in the configuration files located at: test/e2e/$BrandUat/.../OverrideFeatureFlagsValues.kt
To run all tests:
Select the variant for the :e2e module, right-click on e2e, and choose "Run all tests" OR Use the command line: ./gradlew :test:e2e:connected$BrandUatDebugAndroidTest
Utilizing a Helper Class
Same as end to end testing
Region-Specific Testing
Same as end to end testing