0Pricing
SwiftUI Academy · Lekcja

Testy interfejsu z XCUITest

Automatyzuj naciśnięcia i asercje na ekranach

Testy interfejsu z XCUITest to bezpłatna lekcja SwiftUI Academy na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej SwiftUI Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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

Często zadawane pytania

Czy lekcja „Testy interfejsu z XCUITest” jest bezpłatna?

Tak — pełny tekst „Testy interfejsu z XCUITest” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu SwiftUI Academy, przejdź na CoddyKit PRO. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Testy interfejsu z XCUITest”?

Automatyzuj naciśnięcia i asercje na ekranach Ćwiczysz SwiftUI Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć SwiftUI Academy?

Nie wymagamy żadnego doświadczenia. SwiftUI Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.

Ile czasu zajmuje lekcja „Testy interfejsu z XCUITest”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji SwiftUI Academy?

Tak. Każda lekcja SwiftUI Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Testy jednostkowe ViewModeli
  2. Testowanie kodu asynchronicznego
  3. Testy interfejsu z XCUITest
  4. Testowanie oparte na migawkach i podglądach
← Powrót do SwiftUI Academy