SwiftUI Academy · Aula

Testes de Interface com XCUITest

Automatize toques e verificações nas telas.

Aula 3 de 413 etapas

Testes de Interface com XCUITest é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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. 🎉

Grátis para começar

Aprenda Swift com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
30
Aulas
120

Perguntas Frequentes

A aula “Testes de Interface com XCUITest” é grátis?

Sim — o texto completo de “Testes de Interface com XCUITest” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.

O que vou aprender em “Testes de Interface com XCUITest”?

Automatize toques e verificações nas telas. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar SwiftUI Academy?

Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Testes de Interface com XCUITest”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de SwiftUI Academy?

Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Testes Unitários de ViewModels
  2. Testando Código Assíncrono
  3. Testes de Interface com XCUITest
  4. Testes Baseados em Snapshots e Previews
← Voltar para SwiftUI Academy