Espresso
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Espresso を使用すると、簡潔で、美しく、信頼性の高い Android UI テストを作成できます。
次のコード スニペットは、Espresso テストの例を示しています。
Kotlin
@Test
fun greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"))
onView(withId(R.id.greet_button)).perform(click())
onView(withText("Hello Steve!")).check(matches(isDisplayed()))
}
Java
@Test
public void greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"));
onView(withId(R.id.greet_button)).perform(click());
onView(withText("Hello Steve!")).check(matches(isDisplayed()));
}

コア API は小規模で予測可能で、容易に習得できます。しかも、オープンな API を
カスタマイズが可能です。Espresso で想定、インタラクション、アサーションをテストする
ボイラープレート コンテンツやカスタム インフラストラクチャ、
実装の詳細が煩雑になりがちです
Espresso により、テストに要する時間を短縮できます。待ち時間、同期、スリープなどの
実行とポーリングが同時に行われる間、アプリケーションに対して
UI を表示します。
ターゲット ユーザー
Espresso は、自動テストとは何かというと、
不可欠な部分です。ブラックボックス化に使用することも
Espresso の機能を最大限に活用するには、
テスト対象のコードベースです。
同期機能
テストが呼び出されるたびに
onView()
Espresso は、対応する UI アクションやアサーションを
次の同期条件が満たされています。
- メッセージ キューに、Espresso が直ちに実行する必要があるメッセージがない
プロセスです
- 現在実行中の
AsyncTask
のインスタンスはありません
できます。
- デベロッパー定義の
アイドリング リソースがアイドル状態である。
Espresso がこれらのチェックを行うことにより、
一度に実行できる UI アクションまたはアサーションは 1 つのみです。この機能
信頼性の高いテスト結果が得られます
パッケージ
espresso-core
- コアおよび基本的な View
マッチャー、アクション、
記述できます。詳しくは、
基本
とレシピをご覧ください。
espresso-web
- WebView
サポートのリソースが含まれています。
espresso-idling-resource
-
Espresso のバックグラウンド ジョブとの同期メカニズム
espresso-contrib
- 「DatePicker
」を含む外部投稿
RecyclerView
および Drawer
アクション、ユーザー補助機能チェック、
CountingIdlingResource
。
espresso-intents
-
密閉型テスト用のインテントの検証とスタブを行うための拡張機能。
espresso-remote
- Espresso のマルチプロセス機能が含まれています。
最新バージョンの詳細については、
リリースノートをご覧ください。
参考情報
Android テストでの Espresso の使用について詳しくは、
ご覧ください
サンプル
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# Espresso\n\nUse Espresso to write concise, beautiful, and reliable Android UI tests.\n\nThe following code snippet shows an example of an Espresso test:\n\n\u003cbr /\u003e\n\n### Kotlin\n\n```kotlin\n@Test\nfun greeterSaysHello() {\n onView(withId(R.id.name_field)).perform(typeText(\"Steve\"))\n onView(withId(R.id.greet_button)).perform(click())\n onView(withText(\"Hello Steve!\")).check(matches(isDisplayed()))\n}\n```\n\n### Java\n\n```java\n@Test\npublic void greeterSaysHello() {\n onView(withId(R.id.name_field)).perform(typeText(\"Steve\"));\n onView(withId(R.id.greet_button)).perform(click());\n onView(withText(\"Hello Steve!\")).check(matches(isDisplayed()));\n}\n```\n\n\u003cbr /\u003e\n\nThe core API is small, predictable, and easy to learn and yet remains open for\ncustomization. Espresso tests state expectations, interactions, and assertions\nclearly without the distraction of boilerplate content, custom infrastructure,\nor messy implementation details getting in the way.\n\nEspresso tests run optimally fast! It lets you leave your waits, syncs, sleeps,\nand polls behind while it manipulates and asserts on the application\nUI when it is at rest.\n\nTarget audience\n---------------\n\nEspresso is targeted at developers, who believe that automated testing is an\nintegral part of the development lifecycle. While it can be used for black-box\ntesting, Espresso's full power is unlocked by those who are familiar with the\ncodebase under test.\n\nSynchronization capabilities\n----------------------------\n\nEach time your test invokes\n[`onView()`](/reference/androidx/test/espresso/Espresso#onView(org.hamcrest.Matcher%3Candroid.view.View%3E)),\nEspresso waits to perform the corresponding UI action or assertion until the\nfollowing synchronization conditions are met:\n\n- The message queue doesn't have any messages that Espresso needs to immediately process.\n- There are no instances of [AsyncTask](/reference/android/os/AsyncTask) currently executing a task.\n- All developer-defined [idling resources](/training/testing/espresso/idling-resource) are idle.\n\nBy performing these checks, Espresso substantially increases the likelihood that\nonly one UI action or assertion can occur at any given time. This capability\ngives you more reliable and dependable test results.\n\nPackages\n--------\n\n- `espresso-core` - Contains core and basic `View` matchers, actions, and assertions. See [Basics](/training/testing/espresso/basics) and [Recipes](/training/testing/espresso/recipes).\n- [`espresso-web`](/training/testing/espresso/web) - Contains resources for `WebView` support.\n- [`espresso-idling-resource`](/training/testing/espresso/idling-resource) - Espresso's mechanism for synchronization with background jobs.\n- `espresso-contrib` - External contributions that contain `DatePicker`, `RecyclerView` and `Drawer` actions, accessibility checks, and `CountingIdlingResource`.\n- [`espresso-intents`](/training/testing/espresso/intents) - Extension to validate and stub intents for hermetic testing.\n- `espresso-remote` - Location of Espresso's [multi-process](/training/testing/espresso/multiprocess) functionality.\n\nYou can learn more about the latest versions by reading the\n[release notes](/topic/libraries/testing-support-library/release-notes).\n\nAdditional resources\n--------------------\n\nFor more information about using Espresso in Android tests, consult the\nfollowing resources.\n\n### Samples\n\n- [Espresso Code Samples](https://github.com/googlesamples/android-testing) includes a full selection of Espresso samples.\n- [BasicSample](https://github.com/android/testing-samples/tree/main/ui/espresso/BasicSample): Basic Espresso sample.\n- [(more...)](/training/testing/espresso/additional-resources#samples)"]]