動作 UI テスト
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
動作 UI テストは、UI 階層を分析して UI 要素のプロパティにアサーションを適用するテストです。
Jetpack フレームワーク
Jetpack には、UI テストを作成するための API を提供するさまざまなフレームワークが含まれています。
- Espresso テスト フレームワーク(Android 4.0.1、API レベル 14 以降)には、単一のターゲット アプリ内の ビューでのユーザー インタラクションをシミュレートする UI テストを作成するための API が用意されています。Espresso を使用する主な利点は、テスト アクションとテスト対象アプリの UI が自動的に同期されることです。Espresso はメインスレッドがアイドル状態になったタイミングを検出するので、適切な時点でテストコマンドを実行できます。これにより、テストの信頼性が向上します。
- Jetpack Compose(Android 5.0、API レベル 21 以降)には、Compose の画面とコンポーネントを起動して操作するためのテスト API のセットが用意されています。Compose 要素とのインタラクションはテストと同期され、時間、アニメーション、再コンポーズを完全に制御できます。
- UI Automator(Android 4.3、API レベル 18 以上)は、システムアプリとインストール済みアプリにまたがるアプリ間の UI 機能テストに適した UI テスト フレームワークです。UI Automator API を使用すると、テスト端末上で設定メニューやアプリ ランチャーを開くなどの操作が可能になります。
- Robolectric(Android 4.1、API レベル 16 以降)を使用すると、エミュレータやデバイスではなく、通常の JVM を使用して、ワークステーションや継続的インテグレーション環境で実行されるローカルテストを作成できます。Espresso または Compose のテスト API を使用して UI コンポーネントを操作できます。
参考情報
UI テストの作成について詳しくは、以下のリソースをご覧ください。
ドキュメント
Codelab
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# Behavior UI Tests\n\nBehavior UI tests are tests that analyze the UI hierarchy to make assertions\non the properties of the UI elements.\n\nJetpack frameworks\n------------------\n\nJetpack includes various frameworks that provide APIs for writing UI tests:\n\n- The **[Espresso testing framework](/training/testing/espresso)** (Android 4.0.1, API level 14 or higher) provides APIs for writing UI tests to simulate user interactions with *Views* within a single target app. A key benefit of using Espresso is that it provides automatic synchronization of test actions with the UI of the app you are testing. Espresso detects when the main thread is idle, so it is able to run your test commands at the appropriate time, improving the reliability of your tests.\n- **[Jetpack Compose](/jetpack/compose)** (Android 5.0, API level 21 or higher) provides a set of [*testing APIs*](/jetpack/compose/testing) to launch and interact with Compose screens and components. Interactions with Compose elements are synchronized with tests and have complete control over time, animations and recompositions.\n- **[UI Automator](/training/testing/ui-automator)** (Android 4.3, API level 18 or higher) is a UI testing framework suitable for cross-app functional UI testing across system and installed apps. The UI Automator APIs allows you to perform operations such as opening the Settings menu or the app launcher on a test device.\n- **[Robolectric](/training/testing/local-tests/robolectric)** (Android 4.1, API level 16 or higher) lets you create *local* tests that run on your workstation or continuous integration environment in a regular JVM, instead of on an emulator or device. It can use Espresso or Compose testing APIs to interact with UI components.\n\nAdditional resources\n--------------------\n\nFor more information about creating UI tests, consult the following resources.\n\n### Documentation\n\n- [Build instrumented tests](/training/testing/instrumented-tests)\n- [Espresso](/training/testing/espresso)\n- [Compose Testing](/jetpack/compose/testing)\n\n### Codelabs\n\n- [Introduction to Test Doubles and Dependency Injection](/codelabs/advanced-android-kotlin-training-testing-test-doubles)"]]