Test dell'interfaccia utente sul comportamento
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I test di interfaccia utente di comportamento sono test che analizzano la gerarchia dell'interfaccia utente per fare asserzioni sulle proprietà degli elementi dell'interfaccia utente.
Framework Jetpack
Jetpack include vari framework che forniscono API per la scrittura di test dell'interfaccia utente:
- Il framework di test Espresso (Android 4.0.1, livello API 14 o successivo) fornisce API per la scrittura di test dell'interfaccia utente al fine di simulare le interazioni degli utenti con gli elementi View all'interno di una singola app di destinazione. Un vantaggio chiave dell'utilizzo di Espresso è la sincronizzazione automatica delle azioni di test con l'interfaccia utente dell'app che stai testando. Espresso rileva quando il thread principale è inattivo, pertanto è in grado di eseguire i comandi di test al momento opportuno, migliorando l'affidabilità dei test.
- Jetpack Compose (Android 5.0, livello API 21 o versioni successive) fornisce un insieme di API di test per avviare e interagire con le schermate e i componenti di Compose. Le interazioni con gli elementi di Compose
vengono sincronizzate con i test e hanno il controllo completo su tempo, animazioni e ricostruzioni.
- UI Automator (Android 4.3, livello API 18 o versioni successive) è un framework di test dell'interfaccia utente adatto per i test di interfaccia utente funzionali tra app su sistema e app installate. Le API UI Automator ti consentono di eseguire operazioni come aprire il menu Impostazioni o il programma di avvio app su un dispositivo di test.
- Robolectric (Android 4.1, livello API 16 o versioni successive) consente di creare test locali eseguiti sulla workstation o sull'ambiente di integrazione continua in una JVM normale, anziché su un emulatore o un dispositivo. Può utilizzare le API di test Espresso o Compose per interagire con i componenti dell'interfaccia utente.
Risorse aggiuntive
Per ulteriori informazioni sulla creazione di test dell'interfaccia utente, consulta le seguenti risorse.
Documentazione
Codelab
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)"]]