Feature: Cloud Testing API + Tool Results API integration (testing/v1, toolresults/v1beta3)
Summary
Integrate the Google Cloud Testing API (testing/v1) and Cloud Tool Results API (toolresults/v1beta3) to enable running Firebase Test Lab tests (robo, instrumentation, game-loop) on real and virtual Android devices directly from the gplay CLI, and retrieving structured test results, performance metrics, and artifacts — all without leaving the terminal.
Why this is applicable to Google Play
Testing before release is critical to Play Store quality. Firebase Test Lab is Google's recommended pre-release testing infrastructure, running apps on real devices in Google data centers. The gplay CLI already manages tracks, releases, and rollouts — adding automated testing closes the gap between "upload a build" and "ship with confidence." Developers can run robo tests against a release candidate, verify instrumentation tests pass on target devices, and gate promotions on test results, all from the same CLI they use for everything else.
Problem
Today, developers must switch to the Firebase Console, Android Studio, or the gcloud CLI to run Test Lab tests. There is no way to:
- Trigger a test run from the same tool that manages Play Console releases
- Poll for test completion and stream progress in CI pipelines using gplay
- Retrieve test results, logs, screenshots, and performance metrics in JSON/table/markdown format
- Gate a release promotion on test pass/fail status
- List available devices and OS versions for test matrix planning
- Download test artifacts (videos, logcat, screenshots) to local disk
This forces context-switching between tools and makes it harder to build end-to-end release automation pipelines.
Goals
- Add a
gplay testcommand group for Cloud Testing API operations - Add a
gplay test resultssubgroup for Tool Results API operations - Support all three Android test types: robo, instrumentation, and game-loop
- Enable device/environment discovery for test matrix planning
- Provide structured output (JSON, table, markdown) for all commands
- Support polling/waiting for test completion with
--waitflag - Enable artifact download (videos, screenshots, logcat) via GCS integration
- Follow existing CLI patterns (ffcli, shared utilities, context timeouts)
- Lay groundwork for CI integration (exit codes based on test outcome)
Proposed Commands
Test Execution
# Run a Robo test
gplay test run robo \
--project my-gcp-project \
--app path/to/app.apk \
--device model=Pixel6,version=33,locale=en,orientation=portrait \
--device model=Pixel8,version=34,locale=en,orientation=portrait \
--timeout 300s \
--robo-directives "text:username_field=testuser,click:login_button" \
--robo-script path/to/script.json \
--no-video \
--no-perf-metrics \
--wait \
--output json
# Run an Instrumentation test
gplay test run instrumentation \
--project my-gcp-project \
--app path/to/app.apk \
--test-apk path/to/test.apk \
--device model=Pixel6,version=33 \
--test-targets "class com.example.LoginTest" \
--test-runner-class androidx.test.runner.AndroidJUnitRunner \
--use-orchestrator \
--sharding uniform --shard-count 4 \
--flaky-test-attempts 2 \
--fail-fast \
--wait
# Run a Game Loop test
gplay test run game-loop \
--project my-gcp-project \
--app path/to/game.apk \
--device model=oriole,version=33 \
--scenario-numbers 1,2,3 \
--scenario-labels "level1,boss_fight" \
--wait
# Cancel a running test
gplay test cancel \
--project my-gcp-project \
--matrix-id MATRIX_ID
# Get test matrix status
gplay test get \
--project my-gcp-project \
--matrix-id MATRIX_ID \
--output table
Device & Environment Discovery
# List available Android devices
gplay test devices list \
--output table
# List available Android OS versions
gplay test devices versions \
--output table
# List available locales
gplay test devices locales \
--output table
# List network configurations
gplay test devices network-profiles \
--output table
# Get APK details (manifest, permissions, etc.)
gplay test apk-details \
--app path/to/app.apk \
--output json
Test Results (Tool Results API)
# List test histories for a project
gplay test results histories \
--project my-gcp-project \
--paginate \
--output table
# List executions in a history
gplay test results executions \
--project my-gcp-project \
--history-id HISTORY_ID \
--paginate \
--output table
# Get execution details (outcome, timing, environment)
gplay test results execution \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--output json
# List steps (individual test runs per device)
gplay test results steps \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--paginate \
--output table
# Get step details (pass/fail, duration, logs)
gplay test results step \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--step-id STEP_ID \
--output json
# List test cases within a step
gplay test results test-cases \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--step-id STEP_ID \
--paginate \
--output table
# List environments (shard summaries)
gplay test results environments \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--paginate \
--output table
# Get performance metrics summary
gplay test results perf-summary \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--step-id STEP_ID \
--output json
# List performance sample series (CPU, memory, network, graphics)
gplay test results perf-series \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--step-id STEP_ID \
--filter cpu,memory \
--output table
# List screenshot clusters
gplay test results screenshots \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--output table
# List step thumbnails
gplay test results thumbnails \
--project my-gcp-project \
--history-id HISTORY_ID \
--execution-id EXECUTION_ID \
--step-id STEP_ID \
--paginate
Artifact Downloads
# Download all artifacts for a test matrix
gplay test artifacts download \
--project my-gcp-project \
--matrix-id MATRIX_ID \
--output-dir ./test-results/
# Download specific artifact types
gplay test artifacts download \
--project my-gcp-project \
--matrix-id MATRIX_ID \
--output-dir ./test-results/ \
--types video,logcat,screenshots
Implementation Details
APIs and Endpoints
Cloud Testing API v1 (testing.googleapis.com)
| Resource | Methods | Purpose |
|---|---|---|
projects.testMatrices |
create, get, cancel | Execute and manage test runs |
projects.deviceSessions |
create, get, list, patch, cancel | Interactive device sessions |
testEnvironmentCatalog |
get | Device/OS/locale catalogs |
applicationDetailService |
getApkDetails | APK manifest extraction |
Cloud Tool Results API v1beta3 (toolresults.googleapis.com)
| Resource | Methods | Purpose |
|---|---|---|
projects |
getSettings, initializeSettings | Project configuration |
projects.histories |
create, get, list | Group executions by app/build |
projects.histories.executions |
create, get, list, patch | Individual test executions |
projects.histories.executions.steps |
create, get, list, patch, publishXunitXmlFiles, accessibilityClusters | Per-device test steps |
projects.histories.executions.environments |
get, list | Shard/environment summaries |
projects.histories.executions.clusters |
get, list | Screenshot cluster matching |
projects.histories.executions.steps.testCases |
get, list | Individual test case results |
projects.histories.executions.steps.perfSampleSeries |
create, get, list | CPU/memory/network/graphics series |
projects.histories.executions.steps.perfSampleSeries.samples |
batchCreate, list | Raw performance data points |
projects.histories.executions.steps.perfMetricsSummary |
create, get | Aggregated perf metrics |
projects.histories.executions.steps.thumbnails |
list | Step screenshot thumbnails |
Authentication
Both APIs require the https://www.googleapis.com/auth/cloud-platform OAuth scope, which is different from the androidpublisher scope used by the existing Play API client. The new testing client must:
- Request the
cloud-platformscope (orcloud-platform.read-onlyfor read-only operations) - Use the same service account JSON credential flow as
playclientandgcsclient - Support
GPLAY_SERVICE_ACCOUNT/GPLAY_SERVICE_ACCOUNT_JSONenvironment variables - Require a
--projectflag (GCP project ID) since this is a Cloud API, not a Play API
New Packages
internal/
├── cli/
│ └── test/ # Command group package
│ ├── test.go # gplay test (parent command)
│ ├── run_robo.go # gplay test run robo
│ ├── run_instrumentation.go # gplay test run instrumentation
│ ├── run_gameloop.go # gplay test run game-loop
│ ├── run.go # gplay test run (parent)
│ ├── get.go # gplay test get
│ ├── cancel.go # gplay test cancel
│ ├── devices.go # gplay test devices list/versions/locales/network-profiles
│ ├── apk_details.go # gplay test apk-details
│ ├── results.go # gplay test results (parent)
│ ├── results_histories.go # gplay test results histories
│ ├── results_executions.go # gplay test results executions/execution
│ ├── results_steps.go # gplay test results steps/step
│ ├── results_testcases.go # gplay test results test-cases
│ ├── results_environments.go # gplay test results environments
│ ├── results_perf.go # gplay test results perf-summary/perf-series
│ ├── results_screenshots.go # gplay test results screenshots/thumbnails
│ ├── artifacts.go # gplay test artifacts download
│ ├── wait.go # Polling logic for --wait
│ └── *_test.go # Tests for each command
├── testingclient/ # Cloud Testing API client wrapper
│ ├── client.go # Service init, auth with cloud-platform scope
│ ├── testmatrix.go # TestMatrix create/get/cancel helpers
│ ├── catalog.go # Environment catalog helpers
│ └── client_test.go
└── toolresultsclient/ # Tool Results API client wrapper
├── client.go # Service init, auth
├── histories.go # History CRUD
├── executions.go # Execution CRUD
├── steps.go # Step queries
├── testcases.go # Test case queries
├── perf.go # Performance metrics
└── client_test.go
GCS Integration for Artifacts
Test results and artifacts (videos, logcat, screenshots) are stored in GCS. The existing internal/gcsclient package already handles authenticated GCS access with storage/v1 and can be reused for:
- Downloading test result artifacts from the
resultStorage.googleCloudStorage.gcsPathreturned by the Testing API - Listing available artifacts in the results bucket
- Streaming large video files to local disk
Polling for Test Completion
The --wait flag on gplay test run * commands should:
- Create the test matrix via the Testing API
- Poll
testMatrices.getat a configurable interval (default 10s, flag--poll-interval) - Stream state transitions to stderr:
VALIDATING -> PENDING -> RUNNING -> FINISHED - Print per-execution progress messages from
testDetails.progressMessages - On completion, print the final result to stdout in the requested format
- Exit with code 0 on pass, code 1 on failure/error, code 2 on infrastructure error
- Support
--timeoutfor maximum wait duration (distinct from test timeout)
Device Specification Parsing
The --device flag should accept a comma-separated key=value format for readability:
--device model=Pixel6,version=33,locale=en,orientation=portrait
Multiple --device flags create a device list matrix. This mirrors the gcloud CLI format for familiarity.
Output Format Considerations
- JSON output (default): minified, includes full API response for piping/automation
- Table output: summary view with columns like Device | OS | State | Outcome | Duration
- Test case table: Name | Status | Duration | Error (if failed)
- Performance table: Metric | P50 | P90 | P99 values
--waitprogress: stderr for state changes, stdout for final result only
Registration
Register test.TestCommand() in internal/cli/registry/registry.go alongside existing command groups.
Go Client Libraries
Both APIs have official Go client libraries already available via the existing google.golang.org/api dependency (currently v0.272.0):
google.golang.org/api/testing/v1— Cloud Testing APIgoogle.golang.org/api/toolresults/v1beta3— Cloud Tool Results API
No new top-level dependencies required.
Acceptance Criteria
- [ ]
gplay test run robocreates a test matrix with robo configuration and returns the matrix ID - [ ]
gplay test run instrumentationcreates a test matrix with instrumentation configuration, supporting test targets, orchestrator, and sharding - [ ]
gplay test run game-loopcreates a test matrix with game loop scenarios - [ ]
gplay test getretrieves test matrix status and outcome - [ ]
gplay test cancelcancels a running test matrix - [ ]
gplay test devices listreturns the full Android device catalog - [ ]
gplay test devices versionsreturns available Android OS versions - [ ]
gplay test devices localesreturns available test locales - [ ]
gplay test devices network-profilesreturns available network configurations - [ ]
gplay test apk-detailsextracts and displays APK manifest information - [ ]
--waitflag polls until completion and exits with appropriate code (0=pass, 1=fail, 2=infra error) - [ ]
--deviceflag acceptsmodel=X,version=Y,locale=Z,orientation=Wformat; multiple flags create a device list - [ ]
gplay test results historieslists test histories with pagination - [ ]
gplay test results executionslists executions within a history - [ ]
gplay test results stepslists per-device steps with outcome summary - [ ]
gplay test results test-caseslists individual test case results - [ ]
gplay test results environmentslists environment/shard summaries - [ ]
gplay test results perf-summarydisplays aggregated performance metrics - [ ]
gplay test results perf-seriesdisplays CPU/memory/network/graphics time series - [ ]
gplay test results screenshotslists screenshot clusters - [ ]
gplay test artifacts downloaddownloads test artifacts from GCS to local directory - [ ] All commands support
--output json|table|markdown - [ ] All commands use
shared.ContextWithTimeout(uploads useshared.ContextWithUploadTimeout) - [ ] All commands validate required flags and print errors to stderr
- [ ] All commands set
UsageFunc: shared.DefaultUsageFunc - [ ]
--dry-runlogs the API request without executing for write operations (run, cancel) - [ ]
--projectflag is required and validated on all commands - [ ] Service account auth uses
cloud-platformscope for both APIs - [ ]
testingclientandtoolresultsclientpackages have unit tests with mocked HTTP - [ ] CLI-level tests cover flag validation, output formatting, and error paths
- [ ] Command registered in
internal/cli/registry/registry.go - [ ]
gplay test --helpis self-documenting with usage examples
References
- Cloud Testing API REST reference: https://developers.google.com/android/test/reference/rest (discovery:
https://testing.googleapis.com/$discovery/rest?version=v1) - Cloud Tool Results API REST reference: https://developers.google.com/android/test/reference/toolresults/rest (discovery:
https://toolresults.googleapis.com/$discovery/rest?version=v1beta3) - Firebase Test Lab overview: https://firebase.google.com/docs/test-lab
- Firebase Test Lab Android guide: https://firebase.google.com/docs/test-lab/android/command-line
- Go client — Cloud Testing API: https://pkg.go.dev/google.golang.org/api/testing/v1
- Go client — Cloud Tool Results API: https://pkg.go.dev/google.golang.org/api/toolresults/v1beta3
- Go client — GCS (already in use): https://pkg.go.dev/google.golang.org/api/storage/v1
Implementation Checklist
Command & Registration
- [ ] Command group
gplay testingininternal/cli/testing/ - [ ] Subcommands:
environments list,matrices create,matrices get,matrices cancel,results list,results get - [ ] Registered in
internal/cli/registry/registry.go - [ ]
UsageFunc: shared.DefaultUsageFuncset on all commands - [ ] Dedicated client wrappers for
testing/v1andtoolresults/v1beta3APIs - [ ] Long-running operation polling for async test execution
- [ ] Required flags validated with stderr error messages
Tests
- [ ] CLI black-box tests in
internal/cmdtest/testing_test.go - [ ] Unit tests for test matrix construction and result parsing
- [ ] Error paths: missing
--project, invalid APK/test-APK paths, missing device specs
Docs & Help
- [ ]
--helpoutput follows existing conventions - [ ] Command docs regenerated:
gplay docs generate
Validation (before opening PR)
make format
make lint
make test
make build
/tmp/gplay testing --help
/tmp/gplay testing environments list --help
/tmp/gplay testing matrices create --help
/tmp/gplay testing matrices create # missing required flags → stderr error
Addendum to checklist above — docs CI gate:
The PR CI now runs make check-docs on every PR. This means:
- After implementing the command, run
make docsto regenerateGPLAY.md - Commit the updated
GPLAY.mdalongside your code changes - If you forget, the PR check will fail with: "GPLAY.md is out of date"
This ensures every user-facing command, flag, and help text is always reflected in the reference docs.
Consolidating individual feature requests into the roadmap so new visitors see a clean tracker. This item is on the roadmap: #245 — please 👍 there and comment which item you're waiting on. Reopen or file a fresh issue if you start on a PR.