Run Android tests with Marathon Cloud

Evgenii Matsiuk (Eugene Matsyuk)
MarathonLabs
Published in
4 min readJun 20, 2023

--

Marathon Cloud revolutionizes your app testing experience. The platform provides infinite virtual devices and will automatically shard, sort, distribute, and retry your tests, allowing all tests to be completed in a maximum of 15 minutes. The first 50 hours are free!

If you're in search of a way to run your Android UI tests on each PR and wish to compare various solutions, take a look at this series of articles. These articles offer a comprehensive comparison of all the popular cloud-based solutions available.

This article will guide you on how to conduct your initial tests using Marathon Cloud.

Sign up / Sign in

Go to the main page and click on the “Sign up / Sign in” button:

Pass the Login/Registration flow:

Dashboard

Once you have completed the "Sign up / Sign in" process, you will be required to create a team and select the platforms on which you intend to operate:

At last, the dashboard will be visible:

Build app and test APKs

Before initiating the testing process for your application, you’ll require two APK files: one for the application that’s being tested, and another for the tests themselves. Typically, debug variants are utilized for this purpose.

If the primary application resides under the app/ subproject, you can execute the following command to build both the app and test APK:

# file structure
# |
# |--home
# |--john
# |--project <== you are here
# |--app <== it's your primary application
# ...
# |--build.gragle
# |--settings.gradle
./gradlew :app:assembleDebug :app:assembleDebugAndroidTest

Be sure to note the relative paths of the test APK and the app APK, as they will be required for running the tests. In the context of our example, involving the app project and the debug build, these files can be located at the following paths:

- App APK: /home/john/project/app/build/outputs/apk/debug/app-debug.apk
- Test APK: /home/john/project/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk

Run tests with UI

To initiate your tests, the easiest method is to utilize the UI Dashboard. Initially, select the "New Run" button situated at the top-right of the screen:

A dialog box will appear:

Here are the next steps you should take in this box:

  • Select the ANDROID tab.
  • Enter a Title of your choice.
  • Choose the App file. In accordance with the previous example, the apk can be found at this path: /home/john/project/app/build/outputs/apk/debug/app-debug.apk.
  • Select the Test app file. As per the same example, the test apk is located at this path: /home/john/project/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk.
  • Click on the RUN button.

Congratulations on beginning your first test run at Marathon Cloud:

Watching results

Your run should be completed within a timeframe of 15 minutes. Once finished, you can view the reports by clicking on the designated button:

The overview of your test run will appear:

To investigate the causes of any test failures, kindly proceed with the following steps:

Run tests with CLI

There is a way to run your tests with CLI using marathon-cloud-cli. The full documentation of this CLI is available on the Readme page. In this chapter, we are going to consider the basic steps to run your tests.

Install

The installation can be performed using Homebrew. Here’s how to add the MarathonLabs repository:

$brew tap malinskiy/tap

Next, install the Marathon Cloud CLI:

$brew install malinskiy/tap/marathon-cloud

Alternatively, you can download prebuilt binaries for Windows, Linux, or MacOS from the Release page.

API Key

Token creation and management are available on the Tokens page. Generate a token and save it somewhere safe for the next step.

Execution

Now you can start running your tests. Let’s consider the example app described above. Use the following command to execute the CLI with the necessary parameters:

marathon-cloud run android \
--api-key generated_api_key \
--application /home/john/project/app/build/outputs/apk/debug/app-debug.apk \
--test-application /home/john/project/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk

--

--