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

Filter test cases

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.
Note: To filter and run your Cucumber-based Espresso tests, check out the filter Cucumber-based Espresso tests section.

In order to filter test cases, you need to 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 i.e tests annotated with @SmallTest, @MediumTest or @LargeTest in the test-suite A list of test size values (small/medium/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 documetation.

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