UI Tests with XCUITest
Automate taps and assertions on screens.
UI Tests with XCUITest is a free SwiftUI Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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. 🎉
Frequently asked questions
Is the “UI Tests with XCUITest” lesson free?
Yes — the full text of “UI Tests with XCUITest” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.
What will I learn in “UI Tests with XCUITest”?
Automate taps and assertions on screens. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SwiftUI Academy?
No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “UI Tests with XCUITest” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SwiftUI Academy lesson?
Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Unit Testing ViewModels
- Testing Async Code
- UI Tests with XCUITest
- Snapshot & Preview-Driven Testing