Obtain Espresso test reports on BrowserStack App Automate
Get JUnit XML and code coverage test reports for your Espresso test executions on BrowserStack App Automate
Once your Espresso test suite execution is completed, you can access the test reports to view the details about your test execution results across devices. BrowserStack generates the following two reports:
- JUnit XML report
- Test coverage report
Both the reports are available at the session level. A session in case of Espresso refers to execution of a test suite on a single device. However, in case of sharding enabled, a session refers to each shard execution on a device.
- If you want to generate a report of your Cucumber-based Espresso tests, check out the generate test report section.
- You can generate coverage reports for both Espresso and Cucumber sessions. For Android OS 10 and lower, additional configuration is required for generating reports, as defined in the Android 10 and lower coverage report configuration section.
JUnit XML report
You can view the details about your Espresso tests execution on BrowserStack using the JUnit XML report. The schema of the report corresponds to the base schema used by Android Studio’s Gradle build system to generate the report.
Report structure:
Inside the XML report, each session maps to a <testsuite> tag which gives a summary of a test suite execution in terms of total number of tests, number of failed, errored, or skipped tests, duration, and so on. The <testsuite> has nested <properties> and a list of <testcase> elements. Each <testcase> maps to a single test case execution inside a session. If a test case has a failure or an error, there is a nested element <failure> or <error> to denote the error type, message, and stack trace.
Once your Espresso build execution is completed on BrowserStack, you can access the report in the standard JUnit XML format using the REST API:
REST API endpoint:
GET /app-automate/espresso/v2/builds/{build_id}/sessions/{session_id}/report
An example response to the above request is shown below.
<?xml version="1.0"?>
<testsuites>
<testsuite name="com.sample.browserstack.samplecalculator.EnsureInputTests" tests="4" failures="1" skipped="0" timedout="0" errors="0" time="21.225" timestamp="2020-08-31 09:06:02 +0000">
<properties>
<property session_id="y7t1e4296580bd3af29828ffa64e770de9f32b8"/>
<property devicename="Samsung Galaxy S8"/>
<property os="Android"/>
<property version="7.0"/>
</properties>
<testcase name="ensureDivisionWorks" classname="com.sample.browserstack.samplecalculator.EnsureInputTests" result="passed" test_id="fa64e77096580bd3de9f32baf29828ffa632ba5fad668d2" time="2.633" video_url="https://www.browserstack.com/s3-upload/bs-video-logs-aps/s3-ap-south-1/fa64e77096580bd3de9f32baf29828ffa632ba5fad668d2/video-fa64e77096580bd3de9f32baf29828ffa632ba5fad668d2.mp4#t=0,5"/>
<testcase name="ensureMultiplicationWorks" classname="com.sample.browserstack.samplecalculator.EnsureInputTests" result="failed" test_id="fa64e77096580bd3de9f32baf29828ffa632ba5fa855597fc0" time="2.917" video_url="https://www.browserstack.com/s3-upload/bs-video-logs-aps/s3-ap-south-1/fa64e77096580bd3de9f32baf29828ffa632ba5fa855597fc0/video-fa64e77096580bd3de9f32baf29828ffa632ba5fa855597fc0.mp4#t=13,19">
<failure>java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileOutputStream android.content.Context.openFileOutput(java.lang.String, int)' on a null object reference
</failure>
</testcase>
</testsuite>
</testsuites>
Test coverage report
The test coverage report allows you to track the percentage of your main app code that your Espresso tests have covered. You can use it to determine whether you have adequately tested the classes, methods, and lines of code that make up your app. To generate a code coverage report for the executed tests on BrowserStack, follow these steps:
Enable code coverage in your Android project and set up JaCoCo
To generate the code coverage report, enable the code coverage support in your Android project using JaCoCo. Update your project’s build.gradle (app level) as shown:
...
apply plugin: 'jacoco'
...
...
android {
...
buildTypes {
debug {
testCoverageEnabled = true
}
...
}
...
}
jacoco {
toolVersion = '<latest_version>' // E.g. '0.8.5'
}
Build your app and test suite files
Build your app and test suite files. Upload your app and test suite files on BrowserStack.
Execute your tests using the coverage parameter
To generate the code coverage report for your Espresso test execution on BrowserStack, pass the coverage parameter as true in the REST API request to start your test execution.
REST API endpoint:
POST /app-automate/espresso/v2/build
| Parameter | Description | Values |
|---|---|---|
coverage |
Enable the code coverage report for your Espresso test execution. |
true or false. Default: false
|
Example cURL request:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"coverage": true, "devices": ["Samsung Galaxy S8-7.0"], "app": "bs://f7c874f21852ba57957a3fdc33f47514288c4ba4", "testSuite": "bs://e994db8333e32a5863938666c3c3491e778352ff", "project": "SampleProject"}' \
-H "Content-Type: application/json"
Retrieve the code coverage report
Once the execution is completed, you can access the coverage report at session level using the REST API.
REST API endpoint:
GET /espresso/v2/builds/{build_id}/sessions/{session_id}/coverage
Example cURL request:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X GET "https://api-cloud.browserstack.com/app-automate/espresso/v2/builds/4d2b4deb810af077d5aed98f479bfdd2e64f36c3/sessions/98g6h1t8u6y7s4g5j10h8o02e64f1hj/coverage"
The API has a binary response, so save it as an empty coverage.ec file on your local machine. Once the coverage report is generated, rename the coverage.ec file to coverage.exec. You can now view the report in Android Studio:
- Open Android Studio.
- Go to Run (>) Show Code Coverage Data or Analyze (>) Show Coverage Data.
- Click (+) and open the
coverage.execfile. You can now view the coverage data for your app. An example coverage report:

We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!