<commit_before># Android Testing Blueprint

A collection of Google's Android testing tools and frameworks, all integrated in a single application project.

## Structure:

- `app/` - Main application
- `app/test/` - Unit tests
- `app/androidTest/` - Instrumentation tests
- `app/androidTestFlavor2/` - Additional Instrumentation tests for Flavor2.
- `module-flavor1-androidTest-only/` - Test-only module with Instrumentation tests for Flavor1
- `module-android-library/` - An Android module (typically a library)
- `module-android-library/androidTest` - Android Tests for the module-android-library
- `module-plain-java/` - A Java module for non-Android code (business logic, utils classes, etc.)
- `module-plain-java/test` - Unit tests for module-plain-java

## Running Tests

### Running Instrumentation Tests

#### In Android Studio
- In the *Build Variants* window, make sure the *Android Instrumentation Tests* option is selected.
- Open a Instrumentation test class like `EspressoTest.java` or `UiAutomatorTest.java`
- Right click on the class and *Run* as Android Test.

#### From command-line via Gradle
- To run all the Instrumentation tests in the `app` module execute:

``` sh
./gradlew app:connectedAndroidTest
```

#### From command-line via adb
- Install the app and the test app on the device. For example:

``` sh
./gradlew app:installFlavor2Debug app:installFlavor2DebugAndroidTest
```

- To run the Instrumentation tests in the `app` module execute:

``` sh
adb shell am instrument -w com.example.android.testing.blueprint.flavor2.test/android.support.test.runner.AndroidJUnitRunner
```

See the [Modules](#modules), [Flavors](#flavors) and custom [Gradle command-line arguments](#custom-gradle-command-line-arguments) sections to learn how to execute tests for specific modules or flavors and pass custom arguments to AndroidJUnitRunner.

### Running Unit Tests
In Android Studio:
- In the *Build Variants* window, make sure the *Unit Tests* option is selected.
- Open a unit/local test unit class like `LocalUnitTest.java`.
- Right click on the class and *Run* as JUnit test.

From command-line via Gradle:
- To run all the local unit tests in `app` execute:

```
./gradlew app:test
```

- To run the local unit tests in a module execute:

```
./gradlew {module}:test
```

## Testing frameworks and APIs

### Espresso
Espresso is a part of the ATSL (Android Testing Support Library) and a framework for writing concise, beautiful, and reliable Android UI tests.

#### Espresso-Core
The core API is small, predictable, and easy to learn API which. Espresso enables  testing of state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way.

Espresso tests run optimally fast! Leave your waits, syncs, sleeps, and polls behind and let Espresso gracefully manipulate and assert on the application UI when it is at rest.

To get started with Espresso, refer to our [EspressoBasicSample](https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSample)

#### Espresso-Contrib
Espresso Contrib is an extension to Espresso which contains support for the most commonly used Android widgets and support library extension, for instance, RecyclerView.

#### Espresso-Intents
Espresso Intents is a great way to do hermetic inter app testing. It works essentially like [Mockito](https://code.google.com/p/mockito/) and allows for Intent verification and stubbing. To learn more, please refer to our Espresso Intents samples:
[IntentsBasicSample](https://github.com/googlesamples/android-testing/tree/master/ui/espresso/IntentsBasicSample)
[IntentsAdvancedSample](https://github.com/googlesamples/android-testing/tree/master/ui/espresso/IntentsAdvancedSample)
<commit_msg>Adds documentation on how to filter local unit tests<commit_after># Android Testing Blueprint

A collection of Google's Android testing tools and frameworks, all integrated in a single application project.

## Structure:

- `app/` - Main application
- `app/test/` - Unit tests
- `app/androidTest/` - Instrumentation tests
- `app/androidTestFlavor2/` - Additional Instrumentation tests for Flavor2.
- `module-flavor1-androidTest-only/` - Test-only module with Instrumentation tests for Flavor1
- `module-android-library/` - An Android module (typically a library)
- `module-android-library/androidTest` - Android Tests for the module-android-library
- `module-plain-java/` - A Java module for non-Android code (business logic, utils classes, etc.)
- `module-plain-java/test` - Unit tests for module-plain-java

## Running Tests

### Running Instrumentation Tests

#### In Android Studio
- In the *Build Variants* window, make sure the *Android Instrumentation Tests* option is selected.
- Open a Instrumentation test class like `EspressoTest.java` or `UiAutomatorTest.java`
- Right click on the class and *Run* as Android Test.

#### From command-line via Gradle
- To run all the Instrumentation tests in the `app` module execute:

``` sh
./gradlew app:connectedAndroidTest
```

#### From command-line via adb
- Install the app and the test app on the device. For example:

``` sh
./gradlew app:installFlavor2Debug app:installFlavor2DebugAndroidTest
```

- To run the Instrumentation tests in the `app` module execute:

``` sh
adb shell am instrument -w com.example.android.testing.blueprint.flavor2.test/android.support.test.runner.AndroidJUnitRunner
```

See the [Modules](#modules), [Flavors](#flavors) and custom [Gradle command-line arguments](#custom-gradle-command-line-arguments) sections to learn how to execute tests for specific modules or flavors and pass custom arguments to AndroidJUnitRunner.

### Running Unit Tests
In Android Studio:
- In the *Build Variants* window, make sure the *Unit Tests* option is selected.
- Open a unit/local test unit class like `LocalUnitTest.java`.
- Right click on the class and *Run* as JUnit test.

From command-line via Gradle:
- To run all the local unit tests in `app` execute:

```
./gradlew app:test
```

- To run the local unit tests in a module execute:

```
./gradlew :{module}:test
```

- To filter local unit tests to run, you can use:

```
./gradlew :app:testFlavor1DebugUnitTest --tests "com.example.android.testing.blueprint.*"
```

In general, in a project with no flavors:

```
./gradlew :{module}:testDebugUnitTest --tests {test-filter}
```

Note that you cannot use `./gradlew :app:test` or `./gradlew test` with a filter. Read the [gradle documentation on test filtering](https://docs.gradle.org/current/userguide/java_plugin.html#test_filtering) for more information.

## Testing frameworks and APIs

### Espresso
Espresso is a part of the ATSL (Android Testing Support Library) and a framework for writing concise, beautiful, and reliable Android UI tests.

#### Espresso-Core
The core API is small, predictable, and easy to learn API which. Espresso enables  testing of state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way.

Espresso tests run optimally fast! Leave your waits, syncs, sleeps, and polls behind and let Espresso gracefully manipulate and assert on the application UI when it is at rest.

To get started with Espresso, refer to our [EspressoBasicSample](https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSample)

#### Espresso-Contrib
Espresso Contrib is an extension to Espresso which contains support for the most commonly used Android widgets and support library extension, for instance, RecyclerView.

#### Espresso-Intents
Espresso Intents is a great way to do hermetic inter app testing. It works essentially like [Mockito](https://code.google.com/p/mockito/) and allows for Intent verification and stubbing. To learn more, please refer to our Espresso Intents samples:
[IntentsBasicSample](https://github.com/googlesamples/android-testing/tree/master/ui/espresso/IntentsBasicSample)
[IntentsAdvancedSample](https://github.com/googlesamples/android-testing/tree/master/ui/espresso/IntentsAdvancedSample)

{'fraction_non_alphanumeric': 0.09299191374663072, 'fraction_numerical': 0.0018377848566527811, 'mean_word_length': 4.79347054648687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5915961', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2229, 'n_words': 916}