Code Coverage
Overview
Measuring Test Coverage for Espresso Tests
Code Coverage in RobusTest allows you to measure how much of your application code is exercised during Espresso test runs. When enabled, RobusTest automatically instruments each test execution to generate coverage data and makes the resulting coverage file available as a test artifact at the end of each test case attempt.
Note: Code Coverage is supported for Espresso (Android) tests only.
Enabling Code Coverage in Job Run API
To configure RobusTest to handle the code coverage feature when running your Espresso tests, set the codeCoverage flag to true in the framework section of your job payload.
You can also optionally set codeCoverageFolderPath to specify where the coverage file should be stored on the device. If not specified, it defaults to /sdcard.
Example Payload
{
"framework": {
"codeCoverage": true,
"codeCoverageFolderPath": "/sdcard/Download"
}
}
Job Payload Attributes
| Attribute | Type | Required | Default | Description |
|---|---|---|---|---|
codeCoverage |
boolean | Yes | false |
Enables code coverage collection for the Espresso test run |
codeCoverageFolderPath |
string | No | /sdcard |
Path on the device where the coverage file will be stored |
How It Works
When you set the codeCoverage flag to true, RobusTest ensures that with each Espresso test invocation the following key-value pairs are sent with the test execution command:
| Key | Value |
|---|---|
coverageFile |
{codeCoverageFolderPath}/{jobID}_{testResultID}_coverage.ec |
emma |
true |
coverage |
true |
The following string is appended to the test execution command:
-e coverageFile /sdcard/Download/{jobID}_{testResultID}_coverage.ec -e emma true -e coverage true
Note: Any existing
.eccoverage files on the device are automatically removed before each test run to ensure a clean state.
Coverage File Naming Convention
Each coverage file is uniquely named using the job and test result identifiers:
{codeCoverageFolderPath}/{jobID}_{testResultID}_coverage.ec
Example:
/sdcard/Download/64a1f3c2e4b0a1234567890a_64a1f3c2e4b0a1234567890b_coverage.ec
This ensures that each test case attempt produces its own distinct coverage file, avoiding conflicts across parallel or sequential runs.
Accessing the Coverage File
At the end of each test case attempt, the corresponding coverage file is pulled from the device and made available at the test artifact API.
The coverage file for a given test result can be accessed at:
[Device Lab URL]/v3/log/{testResultID}/codeCoverage
Example:
https://your-robustest-instance.com/v3/log/64a1f3c2e4b0a1234567890b/codeCoverage
Authentication: You will need to authenticate using your access key when calling this API endpoint.
Error States
If an issue occurs during coverage file collection, RobusTest records one of the following error states against the test result:
| Status Code | Description |
|---|---|
501 |
Coverage file not found on the device after test execution |
502 |
Coverage file was found but could not be pulled from the device |
503 |
Coverage file was pulled but could not be uploaded to storage |
These errors are surfaced in the test result details and can be used to diagnose coverage collection failures.
Related Documentation
See Also:
- Run Settings — Job payload configuration and run settings reference
- Manual Session — Manual testing session management and workflows
