Mobile Automated Tests with CircleCI and Genymotion SaaS

2024-04-23

> Note: The following article is a reproduction of authored and authorized by Ellinor Kwok.

Efficiently testing mobile apps at every stage of the application lifecycle is challenging. Many companies are adopting tools to help them create, automate, and orchestrate tests on mobile devices. Continuous integration and deployment (CI/CD) tools are among these tools. Having a CI tool isn’t enough. Devices are also needed to run tests. By partnering with CircleCI, the article provides the full continuous integration workflow.

provides Android virtual devices on the Cloud with various configurations and Android versions. is a cloud continuous integration server. CircleCI helps teams get faster builds, shorter feedback lifecycles, and simplified pipeline maintenance.

The integration of Genymotion SaaS is now available on CircleCI as an . QA engineers can integrate Genymotion SaaS in test cases on CircleCI. QA engineers can reuse jobs, commands, and executors to run tests on chosen devices.

This article covers Espresso written tests but any other testing framework can also be used.

To run tests in parallel with CircleCI, multiple devices must run tests at the same time. A CircleCI plan must support more than one job at a time.

1. Create your test workflow with config.yml file

Before setting up an Android project on CircleCI, create the workflow to build the application. Start Genymotion SaaS devices. Run the tests. Stop the devices. Everything is done through a config.yml file in the .circleci/ directory in the project root directory.

Genymotion SaaS Cloud account credentials need to be set as environment variables.

The article covers two examples. The first example uses Start/Stop Genymotion SaaS devices with a single predefined job. The second example uses orb commands in a job.

Start & Stop Genymotion SaaS devices

Several parameters are used.

Use the job defined with the orb

The workflow uses the job defined with the orb.

| | basic_workflow: | | | name: "Run Android 9.0" | | | recipe_uuid: 'd8b10016-c02a-41f9-8a91-ce9b44197d21' | | | name: "Run Android 10.0" | | | recipe_uuid: '4c015ada-e64e-4f5d-a320-06cbf6e95648' | | | adb_serial_port: 12345 |

With this single job, authentication on Genymotion SaaS is included. Start and stop devices steps are included in the genymotion-saas/run_tests step. Only recipe_uuid is required. adb_serial_port is optional. recipe_uuid needs to be directly used in the workflow.

Running tests after a commit.

All steps are done with genymotion-saas-orb job

All steps are done with genymotion-saas-orb job.

Use orb commands in your own job

Orb commands can be used in a job.

To start a device ( adb_serial_port is optional)

| | basic_workflow: | | | name: "Run Android 9.0" | | | recipe_uuid: 'd8b10016-c02a-41f9-8a91-ce9b44197d21' | | | name: "Run Android 10.0" | | | recipe_uuid: '4c015ada-e64e-4f5d-a320-06cbf6e95648' | | | adb_serial_port: 12345 |

To stop a device after running the tests, replace genymotion-saas/start-instance with genymotion-saas/stop-instance.

So a job that runs tests on an Android 9 devices will look like:

Run the tests

The tests are run between start and stop instance steps.

To run espresso tests, the article uses the connectedDebugAndroidTest gradle command:

Results after a successful test

Results after a successful test.

Scale your tests by running your tests in parallel

Each genymotion-saas/start-instance step starts one Android virtual device. To start several devices, define as many jobs as many devices to start.

| | android10: | | | recipe_uuid: "70eaaf75-bd9a-406d-9f01-682a5d400c6e" | | | version: 2 | | | build_and_test: | | | - android9 | | | - android10 |

android9 and android10 are jobs with genymotion-saas/start-instance steps. These steps start respectively an Android 9 and Android 10 devices.

To start these devices in parallel, subscribe to the CircleCI plan that enables more than one job to run in parallel.

Running tests in parallel

2. Get running on CircleCI

The setup allows running tests on Genymotion SaaS virtual devices. The article refers to the on how to set up the project to run on CircleCI.

Conclusion

At the end of this tutorial, the article states that a Continuous Integration workflow for an application can be created. The workflow can run tests at scale.

is . An issue can be created. Contributions can be made.

The Android application code sample and the file used in this tutorial are available on .

Thanks to the CircleCI team (special thanks to Kyle Tryon) for all their help!