atest でプラットフォーム コードをテストする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android Studio for Platform(ASfP)は atest
コマンドライン ツールと統合されており、接続されたデバイスまたはエミュレータで IDE から直接テストを実行できます。
前提条件
- AOSP ソースコードで ASfP プロジェクトを開きます。
- コードをビルドして、デバイスまたはエミュレータに書き込むことに成功している。
source build/envsetup.sh
と lunch
を使用してビルド環境を初期化します。
テストを実行する
ASfP の atest
を使用してテストを実行する方法はいくつかあります。
ガターの実行アイコン: [実行] アイコン play_circle をクリックします。
をクリックします。
右クリック メニュー: [Project] ウィンドウまたはエディタでテストファイル、クラス、メソッドを右クリックし、[Run 'atest'] を選択します。
ターミナルを使用する: ASfP で統合ターミナルを開き([View] > [Tool Windows] > [Terminal])、atest
コマンドを直接実行します。(例: bash
atest MyTestModule
atest MyTestClass#myTestMethod
)。
テスト結果を表示する
テスト結果は、ASfP の [Run] ツール ウィンドウに表示されます。このウィンドウには、テストの進行状況、合格または不合格のステータスが表示され、各テストのログと出力が表示されます。
テスト構成
ガターまたは右クリック メニューからテストを実行すると、ASfP は一時的な実行構成またはデバッグ構成を自動的に作成します。これらの構成を変更して保存すると、特定のオプションやフラグを使用してテストをすばやく再実行できます。
- [Run] > [Edit Configurations] に移動します。
- 変更する
atest
構成を見つけるか、[+] ボタンをクリックして [atest] を選択し、新しい構成を作成します。
- テスト モジュール、クラス、メソッドを指定し、必要な
atest
コマンドライン オプションを追加します。
テストのヒント
- 対象を絞ったテスト: 時間を節約するために、必要な特定のテストのみを実行します。
Module:Class#Method
形式またはその他の atest
フィルタを使用します。
- エミュレータ スナップショットを使用する: エミュレータでテストを高速に実行するには、スナップショットを使用して既知の良好な状態にすばやく戻すことを検討してください。
- ログを確認する: [実行] ツール ウィンドウのログを使用して、テストの失敗を診断します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-09-04 UTC。
[null,null,["最終更新日 2025-09-04 UTC。"],[],[],null,["Android Studio for Platform (ASfP) integrates with the `atest` command-line\ntool, letting you run tests on your connected device or emulator directly from\nthe IDE.\n\nPrerequisites\n\n- Open an ASfP project with your AOSP source code.\n- Successfully build and flash your code to a device or emulator.\n- Initialize your build environment using `source build/envsetup.sh` and `lunch`.\n\nRun tests\n\nYou can run tests using `atest` in ASfP in several ways:\n\n- **Gutter run icons:** Click the **Run** icon play_circle\n\n next to a test class or method in the editor to run that specific test.\n- **Right-click menu:** Right-click on a test file, class, or method in the\n Project window or editor and select **Run 'atest'**.\n\n- **Using the terminal:** Open the integrated terminal in ASfP (**View \\\u003e Tool\n Windows \\\u003e Terminal** ) and run `atest` commands directly. For example: `bash\n atest MyTestModule\n atest MyTestClass#myTestMethod`\n\nView test results\n\nTest results are displayed in the **Run** tool window within ASfP. This window\nshows the test progress, pass or fail status, and provides logs and output for\neach test.\n\nTest configurations\n\nWhen you run a test from the gutter or right-click menu, ASfP automatically\ncreates a temporary run or debug configuration. You can modify and save these\nconfigurations to quickly re-run tests with specific options or flags:\n\n1. Go to **Run \\\u003e Edit Configurations**.\n2. Find the `atest` configuration you want to modify or create a new one by clicking the **+** button and selecting **atest**.\n3. Specify the test module, class, method, and add any necessary `atest` command-line options.\n\nTips for testing\n\n- **Targeted testing:** Run only the specific tests you need to save time. Use the format `Module:Class#Method` or other `atest` filters.\n- **Use emulator snapshots:** For faster test runs on emulators, consider using snapshots to quickly revert to a known good state.\n- **Check logs:** Use the logs in the **Run** tool window to diagnose any test failures."]]