Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy

View test reports

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. The two reports that are generated:

  1. JUnit XML report
  2. Test coverage report

Both the reports are available at the session level. A session in case of Espresso refers to execution of 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 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 here.

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 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, no of failed/errored/skipped tests, duration etc. 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 will be 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. In order to generate a code coverage report for the executed tests on BrowserStack, you need to follow the steps:

Step 1: Enable code coverage in your Android project and setup Jacoco

For generating the code coverage report, you need to 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'
}

Step 2: Build your app and test-suite files

Build your app and test-suite file. Upload your app and test-suite files on BrowserStack.

Step 3: Execute your tests using coverage parameter

In order to generate the code coverage report for your Espresso test execution on BrowserStack, you need to 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/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"

Step 4: 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 will have a binary response so you can save it an empty coverage.ec file on your local machine. Once the coverage report has been generated, rename the coverage.ec file to coverage.exec. You can now view the report in the Android Studio:

  1. Open Android Studio.
  2. Go to RunShow Code Coverage Data or AnalyzeShow Coverage Data.
  3. Click (+) and open the coverage.exec file. You will be able to view the coverage data for your app. An example coverage report:

Android Studio Espresso Code Coverage

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy