It can be hard to automate game testing when gaming apps are built on different UI frameworks. Game Loop tests allow you to integrate your native tests with Test Lab and easily run them on devices you select. A Game Loop test runs your test through your gaming app while simulating the actions of a real player. This guide shows you how to run a Game Loop test, then view and manage your test results in the Firebase console.
Depending on your game engine, you can implement tests with single or multiple loops. A loop is a full or partial run-through of your test on your gaming app. Game loops can be used to:
- Run a level of your game the same way an end user would play it. You can either script the input of the user, let the user be idle, or replace the user with an AI if it makes sense in your game (e.g., say you have a race car gaming app and already have an AI implemented. You can easily put an AI driver in charge of the user's input).
- Run your game at the highest quality setting to see if devices support it.
- Run a technical test (compile multiple shaders, execute them, check that the output is as expected, etc).
You can run a Game Loop test on a single test device, a set of test devices, or on Test Lab . However, we don't recommend running Game Loop tests on virtual devices because they have lower graphics frame rates than physical devices.
Before you begin
To implement a test, you must first configure your app for Game Loop tests.
-
In your app manifest, add a new intent filter to your activity :
<activity android:name=".MyActivity"> <intent-filter> <action android:name="com.google.intent.action.TEST_LOOP"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="application/javascript"/> </intent-filter> <intent-filter> ... (other intent filters here) </intent-filter> </activity>
This allows Test Lab to launch your game by triggering it with a specific intent.
-
In your code (we recommend inside the
onCreate
method declaration), add the following:Kotlin
val launchIntent = intent if ( launchIntent . action == "com.google.intent.action.TEST_LOOP" ) { val scenario = launchIntent . getIntExtra ( "scenario" , 0 ) // Code to handle your game loop here }
Java
Intent launchIntent = getIntent (); if ( launchIntent . getAction (). equals ( "com.google.intent.action.TEST_LOOP" )) { int scenario = launchIntent . getIntExtra ( "scenario" , 0 ); // Code to handle your game loop here }
This allows your activity to check the intent that launches it. You can also add this code later if you prefer (e.g., after initially loading your game engine).
-
Recommended: At the end of the test, add:
Kotlin
yourActivity . finish ()
Java
yourActivity . finish ();
This closes your app when the Game Loop test is complete. The test relies on your app's UI framework to start the next loop, and closing your app tells it that the test is finished.
Create and run a Game Loop test
After you configure your app for Game Loop tests, you can immediately create a test and run it in your gaming app. You can choose to run a test in Test Lab using either the Firebase console or the gcloud command line interface (CLI) , or on a local device using the Test Loop Manager .
Run on a local device
Test Lab 's Test Loop Manageris an open source app that helps you integrate Game Loop tests and run them on your local devices. It also allows your Quality Assurance team to run the same game loops on their devices.
To run a test on a local device using the Test Loop Manager:
- Download the Test Loop Manager
on a phone or tablet and install it by running:
adb install testloopmanager.apk
- On your device, open the Test Loop Appsapp on your phone or tablet. The app displays a list of apps on your device that can be run with game loops. If you don't see your gaming app here, make sure your intent filter matches the one described in the first step of the Before you begin section .
- Select your gaming app, then select the number of loops you want to run. Note: At this step, you can choose to run a subset of loops instead of just one loop. For more information on running multiple loops at once, see Optional features .
- Click Run test. Your test starts running immediately.
Run in Test Lab
You can run a Game Loop test in Test Lab using either the Firebase console or the gcloud CLI. Before you begin, if you haven't already, open the Firebase console and create a project.
Use the Firebase console
- In the Firebase console, click Test Lab from the left panel.
- Click Run Your First Test(or Run a Testif your project has previously run a test).
- Select Game Loopas the test type, and then click Continue.
- Click Browse, and then browse to your app's
.apk
file. Note: At this step, you can choose to run a subset of loops instead of just one loop. For more information on running multiple loops at once, see Optional features . - Click Continue.
- Select the physical devices to use to test your app.
- Click Start Tests.
For more information on getting started with the Firebase console, see Start testing with the Firebase console.
Use the gcloud command-line (CLI)
-
If you haven't already, download and install the Google Cloud SDK
-
Sign in to the gcloud CLI using your Google Account:
gcloud auth login
-
Set your Firebase project in gcloud, where
PROJECT_ID
is the ID of your Firebase project:gcloud config set project PROJECT_ID
-
Run your first test:
gcloud firebase test android run \ --type=game-loop --app=<var>path-to-apk</var> \ --device model=herolte,version=23
For more information on getting started with the gcloud CLI, see Start testing from the gcloud command line.
Optional features
Test Lab offers several optional features that let you further customize your tests, including the ability to write output data, support for multiple game loops, and labels for related loops.
Write output data
Your Game Loop test can write output to a file specified in the launchIntent.getData()
method. After you run a test, you can access this
output data in the Test Lab
section of the Firebase
console (see Game Loop test output file example
).
Test Lab
follows best practices for sharing a file between apps described in Sharing a File
.
In your activity’s onCreate()
method, where your intent is located, you
can check your data output file by running following code:
Kotlin
val launchIntent = intent val logFile = launchIntent . data logFile ?. let { Log . i ( TAG , "Log file ${ it . encodedPath } " ) // ... }
Java
Intent launchIntent = getIntent (); Uri logFile = launchIntent . getData (); if ( logFile != null ) { Log . i ( TAG , "Log file " + logFile . getEncodedPath ()); // ... }
If you want to write to the file from the C++ side of your game app, you can pass in the file descriptor instead of the file path:
Kotlin
val launchIntent = intent val logFile = launchIntent . data var fd = - 1 logFile ?. let { Log . i ( TAG , "Log file ${ it . encodedPath } " ) fd = try { contentResolver . openAssetFileDescriptor ( logFile , "w" ) !! . parcelFileDescriptor . fd } catch ( e : FileNotFoundException ) { e . printStackTrace () - 1 } catch ( e : NullPointerException ) { e . printStackTrace () - 1 } } // C++ code invoked here. // native_function(fd);