0Pricing
SwiftUI Academy · Lezione

Test UI con XCUITest

Automatizzi tocchi e asserzioni nelle schermate.

Test UI con XCUITest è una lezione SwiftUI Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento SwiftUI Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso SwiftUI Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

What UI Tests Do

UI tests drive your app like a real person: they tap, type, and swipe, then check the screen reacted correctly. 📱

A Separate Test Target

UI tests live in their own UI Testing target. Xcode adds it when you create the project or from the test navigator later.

Launching the App

Every UI test starts by launching a fresh app instance with XCUIApplication. This gives you a clean state to work from.

let app = XCUIApplication()
app.launch()

Finding Elements

You reach controls through queries like buttons, staticTexts, and textFields. Each query finds elements by their kind on screen.

app.buttons["Add"]

Tapping a Button

Call tap on an element to simulate a finger press. The app responds exactly as it would for a real user.

app.buttons["Add"].tap()

Typing Text

Tap a field first, then send keystrokes with typeText. This is how you fill in forms during a test.

app.textFields["name"].typeText("Sam")

Accessibility Identifiers

Give views a stable accessibilityIdentifier so tests find them even when the visible label changes or is localized.

.accessibilityIdentifier("addButton")

Asserting What Appears

Check the result with exists. It returns true when the element is on screen, confirming your action worked.

XCTAssertTrue(app.staticTexts["Done"].exists)

Waiting for Elements

If content loads after a delay, use waitForExistence with a timeout. The test pauses until the element shows up. ⏳

label.waitForExistence(timeout: 3)

Record to Learn

New to queries? Use Xcode's record button. It writes code as you tap, giving you a starting point to clean up.

Keep UI Tests Few

UI tests are slower than unit tests. Cover key flows like sign-in and checkout, and leave the rest to faster unit tests.

Quick Check

What is the most reliable way for a UI test to find a control?

Recap

You drove the app with XCUITest: launch it, query controls, tap and type, then assert with exists. Real user flows, automated. 🎉

Domande Frequenti

La lezione «Test UI con XCUITest» è gratuita?

Sì — il testo completo di «Test UI con XCUITest» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso SwiftUI Academy, passa a CoddyKit PRO. Il corso SwiftUI Academy include 4 lezioni in totale.

Cosa imparerò in «Test UI con XCUITest»?

Automatizzi tocchi e asserzioni nelle schermate. Eserciti SwiftUI Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare SwiftUI Academy?

Non è richiesta alcuna esperienza precedente. SwiftUI Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Test UI con XCUITest»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione SwiftUI Academy?

Sì. Ogni lezione SwiftUI Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Test unitari dei ViewModel
  2. Testare il codice asincrono
  3. Test UI con XCUITest
  4. Test basati su snapshot e preview
← Torna a SwiftUI Academy