Test platform code with atest
Stay organized with collections
Save and categorize content based on your preferences.
Android Studio for Platform (ASfP) integrates with the atest
command-line
tool, letting you run tests on your connected device or emulator directly from
the IDE.
Prerequisites
- Open an ASfP project with your AOSP source code.
- Successfully build and flash your code to a device or emulator.
- Initialize your build environment using
source build/envsetup.sh
and
lunch
.
Run tests
You can run tests using atest
in ASfP in several ways:
Gutter run icons: Click the Run icon play_circle
next to a test class or method in the editor to run that specific test.
Right-click menu: Right-click on a test file, class, or method in the
Project window or editor and select Run 'atest'.
Using the terminal: Open the integrated terminal in ASfP (View > Tool
Windows > Terminal) and run atest
commands directly. For example: bash
atest MyTestModule
atest MyTestClass#myTestMethod
View test results
Test results are displayed in the Run tool window within ASfP. This window
shows the test progress, pass or fail status, and provides logs and output for
each test.
Test configurations
When you run a test from the gutter or right-click menu, ASfP automatically
creates a temporary run or debug configuration. You can modify and save these
configurations to quickly re-run tests with specific options or flags:
- Go to Run > Edit Configurations.
- Find the
atest
configuration you want to modify or create a new one by
clicking the + button and selecting atest.
- Specify the test module, class, method, and add any necessary
atest
command-line options.
Tips for testing
- Targeted testing: Run only the specific tests you need to save time. Use
the format
Module:Class#Method
or other atest
filters.
- Use emulator snapshots: For faster test runs on emulators, consider
using snapshots to quickly revert to a known good state.
- Check logs: Use the logs in the Run tool window to diagnose any test
failures.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-09-04 UTC.
[null,null,["Last updated 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."]]