Testowanie kodu platformy za pomocą narzędzia atest
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Android Studio for Platform (ASfP) jest zintegrowany z narzędziem wiersza poleceń atest
, co umożliwia uruchamianie testów na podłączonym urządzeniu lub emulatorze bezpośrednio z IDE.
Wymagania wstępne
- Otwórz projekt ASfP z kodem źródłowym AOSP.
- Skompiluj i wgraj kod na urządzenie lub emulator.
- Zainicjuj środowisko kompilacji za pomocą poleceń
source build/envsetup.sh
i lunch
.
Przeprowadzanie testów
Testy w ASfP możesz uruchamiać na kilka sposobów:atest
Ikony uruchamiania na marginesie: kliknij ikonę Uruchom play_circle.
obok klasy lub metody testowej w edytorze, aby uruchomić konkretny test.
Menu po kliknięciu prawym przyciskiem myszy: kliknij prawym przyciskiem myszy plik testowy, klasę lub metodę w oknie Projekt lub w edytorze i wybierz Uruchom „atest”.
Korzystanie z terminala: otwórz zintegrowany terminal w ASfP (Widok > Okna narzędzi > Terminal) i uruchamiaj polecenia atest
bezpośrednio. Na przykład: bash
atest MyTestModule
atest MyTestClass#myTestMethod
Wyświetlanie wyników testu
Wyniki testu są wyświetlane w oknie narzędzia Uruchom w ASfP. W tym oknie
widać postęp testu, stan (pozytywny lub negatywny) oraz dzienniki i dane wyjściowe
każdego testu.
Konfiguracje testowe
Gdy uruchamiasz test z marginesu lub menu kontekstowego, ASfP automatycznie tworzy tymczasową konfigurację uruchamiania lub debugowania. Możesz modyfikować i zapisywać te konfiguracje, aby szybko ponownie uruchamiać testy z określonymi opcjami lub flagami:
- Kliknij Uruchom > Edytuj konfiguracje.
- Znajdź konfigurację
atest
, którą chcesz zmodyfikować, lub utwórz nową, klikając przycisk + i wybierając atest.
- Określ moduł testowy, klasę i metodę oraz dodaj niezbędne
atest
opcje wiersza poleceń.
Wskazówki dotyczące testowania
- Testowanie ukierunkowane: aby zaoszczędzić czas, przeprowadzaj tylko te testy, których potrzebujesz. Użyj formatu
Module:Class#Method
lub innych filtrów atest
.
- Używaj zrzutów emulatora: aby szybciej przeprowadzać testy na emulatorach, możesz używać zrzutów, aby szybko przywracać znany dobry stan.
- Sprawdź logi: użyj logów w oknie narzędzia Uruchom, aby zdiagnozować wszelkie błędy testów.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-09-05 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-09-05 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."]]