---
title: Filter Espresso Tests
description: Define which Espresso tests should run in the cloud. Filter on class,
  size, package and annotations.
source_url:
  html: https://testingbot.com/support/app-automate/espresso/filter
  md: https://testingbot.com/support/app-automate/espresso/filter/index.md
---
# Filter Espresso Test Cases

By default, TestingBot will execute all tests present in the Espresso `.apk`.

The Espresso test runner (which is usually **AndroidJUnitRunner** ) provides multiple options to filter test cases for execution.

You might want to use these filter options for specific use cases, such as:

- Run only specific tests for a bugfix. 
- Only run a subset of tests, for quick smoke testing. Instead of waiting on all your Espresso tests. 
- Run specific tests for specific environments (production, staging, ...) 

Below you'll find the different filter options that TestingBot and Espresso provide.

- [class](https://testingbot.com#class): will run all tests in a specific class 
- [notClass](https://testingbot.com#notClass): will run all tests except the tests in a particular class 
- [size](https://testingbot.com#size): will run a specific test size annotated with `SmallTest`, `MediumTest` or `LargeTest`
- [package](https://testingbot.com#package): will run all tests in a specific Java package 
- [notPackage](https://testingbot.com#notPackage): will run all tests except the tests in a specific package 
- [annotation](https://testingbot.com#annotation): will run all tests with a specific annotation 
- [notAnnotation](https://testingbot.com#notAnnotation): will run all tests except the tests with a specific annotation 
- [numShards](https://testingbot.com#shards): filter test run to a shard of all tests, where numShards is an integer greater than 0 and shardIndex is an integer between 0 (inclusive) and numShards (exclusive) 

## class Filter

To only run Espresso tests for a specific `class`, you can use the class option.

You can pass a list of fully qualified Java class names. See the example below.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --class "com.android.app.one,com.android.app.two"

This will start an Espresso test session on the specified device and only run tests for the classes specified.

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "class": ["com.android.app.one", "com.android.app.two"] }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

This call with start an Espresso test Session on the specific device and only run the Espresso tests for the classNames specified.

## notClass Filter

Use the `notClass` option to run all Espresso tests except for the tests in the classes specified with this option.

You can pass a list of fully qualified Java class names. See the example below.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --not-class "com.android.app.one,com.android.app.two"

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "notClass": ["com.android.app.one", "com.android.app.two"] }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

## size Filter

The `size` option allows you to specify which tests you want to run, depending on the annotated size: `SmallTest`, `MediumTest` or `LargeTest`

You can pass an array of sizes, see below for an example.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --size "small,medium"

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "size": ["small", "medium"] }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

## package Filter

The `package` filter allows you to specify for which package the Espresso tests should run.

You can pass an array of packages, see below for an example.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --package "com.android.one,com.android.two"

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "package": ["com.android.one", "com.android.two"] }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

## notPackage Filter

The `notPackage` filter allows you to indicate that Espresso tests should run for everything except for the packages defined.

You can pass an array of packages, see below for an example.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --not-package "com.android.one,com.android.two"

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "notPackage": ["com.android.one", "com.android.two"] }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

## annotation Filter

The `annotation` filter will run tests annotated with the field (or fields) you specified.

You can pass an array of annotations, see below for an example.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --annotation "com.android.foo.MyAnnotation,com.android.foo.MyAnnotationTwo"

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "annotation": ["com.android.foo.MyAnnotation", "com.android.foo.MyAnnotationTwo"] }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

## notAnnotation Filter

The `notAnnotation` filter will run all tests except those annotated with the field (or fields) you specified.

You can pass an array of notAnnotations, see below for an example.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --not-annotation "com.android.foo.MyAnnotation,com.android.foo.MyAnnotationTwo"

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "notAnnotation": ["com.android.foo.MyAnnotation", "com.android.foo.MyAnnotationTwo"] }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

## shards Filter

You can split your Espresso tests across multiple parallel shards to reduce total run time. Pass `numShards` (total number of shards, an integer greater than 0) and `shardIndex` (which shard this run executes, an integer between 0 inclusive and `numShards` exclusive).

For example, to split into 4 shards and run shard 0 (the first), pass `numShards=4` and `shardIndex=0`. Submit one test run per shard index to run all four shards in parallel.

[CLI](https://testingbot.com#)[cURL](https://testingbot.com#)

    testingbot espresso app.apk app-test.apk \
      --device "Pixel 6" \
      --platform-version "12" \
      --num-shards 4 \
      --shard-index 0

    curl -u api_key:api_secret \
    -X POST "https://api.testingbot.com/v1/app-automate/espresso/:id/run" \
    -d '{ "espressoOptions": { "numShards": 4, "shardIndex": 0 }, "capabilities":[{"version":"12", "deviceName":"Pixel 6", "platformName":"Android"}]}' \
    -H "Content-Type: application/json"

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new)[Slack Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
