Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Filter test cases in Espresso tests on BrowserStack App Automate

Use REST API parameters to filter Espresso test cases by class, package, annotation, or test size.

By default, all test cases included in your Espresso test suite are executed. The Espresso test runner (typically AndroidJUnitRunner) supports multiple options to filter test cases for execution. These options can be useful in multiple scenarios:

  1. Run a quick smoke test to ensure sanity of important functionality.
  2. Run only those test cases that are relevant to a new bug fix.
  3. Split a large test suite into multiple shards and run them in parallel.

To filter and run your Cucumber-based Espresso tests, check out the filter Cucumber-based Espresso tests section.

To filter test cases, pass relevant parameters in the REST API request to start your test execution. These parameters are outlined in the table below.

REST API endpoint:

POST /app-automate/espresso/v2/build
Parameter Description Values
class Filter test cases by selected classes in the test suite A list of fully qualified Java class name
E.g. ["com.android.foo.ClassA"]
package Filter test cases by selected packages in the test suite A list of fully qualified Java package name
E.g. ["com.android.foo"]
annotation Filter test cases by selected annotations in the test suite A list of fully qualified annotation
E.g. ["com.android.foo.MyAnnotation"]
size Filter test cases by specific test size, that is, tests annotated with @SmallTest, @MediumTest, or @LargeTest, in the test suite A list of test size values (small, medium, or large)
E.g. ["small", "medium"]

Example cURL requests:

Execute test cases that belong to particular class names:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"class": ["com.foo.AddToCartClass", "com.foo.CheckoutClass"], "devices": ["Samsung Galaxy S8-7.0"], "app": "bs://f7c874f21852ba57957a3fdc33f47514288c4ba4", "testSuite": "bs://e994db8333e32a5863938666c3c3491e778352ff"}' \
-H "Content-Type: application/json"

Execute test cases that have specific annotations:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"annotation": ["com.foo.SmokeTest"], "devices": ["Samsung Galaxy S8-7.0"], "app": "bs://f7c874f21852ba57957a3fdc33f47514288c4ba4", "testSuite": "bs://e994db8333e32a5863938666c3c3491e778352ff"}' \
-H "Content-Type: application/json"

Execute test cases of specific test size:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"size": ["small","medium"], "devices": ["Samsung Galaxy S8-7.0"], "app": "bs://f7c874f21852ba57957a3fdc33f47514288c4ba4", "testSuite": "bs://e994db8333e32a5863938666c3c3491e778352ff"}' \
-H "Content-Type: application/json"

If your tests fail with a NO TESTS RAN error, refer to the No tests ran documentation.

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 Check Circle