An example of how to mock the network layer in Maestro tests.
You can find more info about the motivation behind this approach in the post The Night’s Watch: Safeguarding store operations
demo.mp4
- Maestro to run the UI tests.
- Docker to manage the mocking service.
- Mocks Server to mock the network responses.
- Start the emulator. You can run your emulator or create one through Maestro:
maestro start-device --platform=android
- Install the
maestro
build variant:
./gradlew installMaestro
- Start Mocks Server:
docker compose -f mocks/docker-compose.yml up
- Run Maestro tests:
maestro test maestro/
There are three different build variants.
- debug: To develop the application.
- release: The final version.
- maestro: The mocked version.
For the sake of simplicity, we've omitted, in purpose, some important pieces in a production application like using ViewModels or adding Retrofit or Ktor for the network calls, as well as adding other types of tests.