All articles
November 24, 2026

SwiftUI previews and testing: a practical workflow for small teams, 2026

Use previews for how a view looks, Swift Testing for logic and XCTest for a few critical flows. A routine a small iOS team can keep.

Hand sketching flowers in a notebook beside a laptop, like drafting a view design before building it in SwiftUI

The short answer

A workable SwiftUI testing workflow for a small team has three layers. Previews show how a view looks. Swift Testing checks what your logic does. A handful of XCTest UI tests protect the flows you cannot afford to break. Each layer answers a different question. None replaces the others.

Small teams get into trouble when they pick one tool and ask it to do everything. Previews can't fail a build. UI tests are too slow and brittle to check every label. This article sets out what each layer is for, how to keep it cheap, and a weekly routine for two or three people. It reflects Apple's own documentation as of November 2026.

Previews cover how a view looks

A preview is a live render of a view inside Xcode. Apple's Xcode overview says you add previews to SwiftUI, UIKit and AppKit views with the preview macro, then configure them in the canvas or in code. In live mode, "your view appears and interacts just like it would on a device or simulator."

Previews are real code running. Apple's WWDC19 session on previews states that Xcode is "actually building and running your code", so assets, logic and user defaults are available. That makes previews good at visual questions and poor at proving anything.

Feed previews sample data, never the network

Keep preview data local. The same session recommends a Preview Assets (Development Assets) catalog, so placeholder images and a JSON file stay out of the shipped app, and advises avoiding network calls in previews. A preview that waits on a server is slow and flaky, and it shows different data each time.

Build one small sample type per model and reuse it across previews and tests. Reusing it keeps the data honest in both places.

One preview per variant that matters

Add a preview for each state a reviewer would want to see, not every combination. A practical set for most screens:

  • The default state with typical data.
  • An empty state and an error state.
  • A large Dynamic Type size. Apple's session shows setting the size category in the environment, or looping over every ContentSizeCategory case.
  • Dark Mode and a small device such as the iPhone SE.

Apple's overview confirms you can adjust device settings, "including in Dark Mode, landscape orientation, or different sized text." To preview a selected or expanded state, expose private @State as a Binding through an inner content view, as the WWDC19 session demonstrates. Our guide to State, Binding, Observable and Environment covers which wrapper to reach for.

A preview is a review aid. It asserts nothing. If a rule matters, such as "the total never shows a negative number", write a test for it.

Unit tests with Swift Testing

Test the logic that feeds your views. Put formatting, validation, sorting and state transitions in view models or plain types, then test those. They run fast and need no simulator UI.

Swift Testing is the framework to use for this. In Apple's Meet Swift Testing session, Apple states: "Swift Testing is now the default choice of testing system for this template in Xcode 16."

The pieces you use daily

The @Test attribute marks a function as a test. Tests can be global functions or methods, and can be async, throws or actor-isolated. No test name prefix is needed.

XCTest's many XCTAssert functions give way to two macros. #expect "accepts ordinary expressions and language operators" and captures the values of subexpressions when it fails, so a failure message shows what each side held. #require throws on failure and ends the test early, and it can unwrap an optional so the rest of the test reads cleanly.

Suites, parameters and tags

Any type that contains @Test functions is implicitly a suite. Apple notes that a separate instance is created for every test function, so structs work well. Use init where you used setUp.

For repeated checks, use parameterized tests instead of a for loop. Each argument appears separately in the Test Navigator, can be re-run on its own, and the arguments can run in parallel. A rounding rule tested against twelve inputs becomes twelve visible results, so a failure points at one input.

Tags let you group tests across suites. Apple's advice is to prefer tags over test names when including or excluding tests from a test plan. A tag such as fast or network is enough to start.

Living with XCTest

You don't have to migrate everything. Both frameworks can sit in one target, and Apple says existing XCTest tests run side by side with Swift Testing tests so you can migrate incrementally. Do not mix assertion styles inside one test: keep XCTAssert in XCTest tests and #expect in Swift Testing tests.

UI tests with XCTest

Keep UI tests few. Apple's WWDC25 session on UI automation says: "Generally, your test suite will have more unit tests than UI tests." UI automation runs independently of your app, so your app models and data are not directly accessible, which makes these tests slower to write and to debug.

UI tests stay in XCTest. The Swift Testing session says to keep using XCTest for "any tests which use UI automation APIs like XCUIApplication or use performance testing APIs like XCTMetric."

What deserves a UI test

Pick flows where a break costs you money or reviews: launch, sign-in, the main purchase or save path, and anything that depends on system behavior a unit test cannot see. Apple lists gestures, VoiceOver, Dynamic Type, languages and right-to-left layouts, and launch performance as natural UI test territory.

Accessibility identifiers and recording

Recording works with no app changes, but identifiers make the result stable. Apple's guidance is that good identifiers are "unique within your entire app, descriptive... and static." Each recorded line offers alternative queries. Prefer identifiers over localized text, use the shortest query for nested views, and use generic queries for dynamic content.

Add explicit waits rather than sleeps. The session names waitForExistence(timeout:) for this. It also lists launchArguments and launchEnvironment, which let a test start the app in a known state, for example with sample data already loaded.

Test plans and CI for a small team

A test plan is the file that ties this together. Apple describes plans as a way to include or exclude tests, set system settings, and manage timeouts, repetitions, parallelization and execution order. Create one plan for fast unit tests that runs on every change and one for UI tests that runs before a release.

Locales belong here. Apple notes that each locale is typically its own configuration, and suggests German for long strings and Arabic or Hebrew for right-to-left layouts. By default, videos and screenshots are kept only for failures, which keeps result bundles small.

Run the plans somewhere other than a single laptop. Apple's overview describes Xcode Cloud as a CI/CD service that can "run automated tests in parallel", and the WWDC25 session says it can run the same plan across devices and languages. If you ship through scripts, see how teams automate builds, signing and submission with Fastlane and run the unit plan as the first gate.

A weekly routine for two or three people

Routines survive when they're small. This one fits in a few hours a week:

Pipeline diagram with five steps: Every change, Every bug fix, Weekly, Before each release and Monthly
Pipeline: A weekly routine for two or three people.
  1. Every change: add or update previews for the states you touched, and run the unit plan before you open a pull request.
  2. Every bug fix: write the failing unit test first, then fix it. Add a tag if the bug came from the network layer.
  3. Weekly: open the preview canvas on your three busiest screens at the largest text size and in Dark Mode, and fix what breaks.
  4. Before each release: run the UI plan on one small and one large device, and read the failure videos.
  5. Monthly: delete or rewrite any UI test that failed for reasons unrelated to the app.

If you want help setting this up for an existing app, Kallos Labs does iOS development and can work inside your repository.

Frequently asked questions

Do SwiftUI previews replace tests?

No. A preview shows one state of a view for a person to judge, and it asserts nothing, so it cannot fail a build. Use previews for how a view looks and tests for what the code does.

Should a new project use Swift Testing or XCTest?

Use Swift Testing for unit tests and XCTest for UI automation. Apple made Swift Testing the default for the Xcode 16 test template, and both frameworks can sit in one target so you can mix them as the project grows.

How many UI tests does a small team need?

Few. Apple says a suite generally has more unit tests than UI tests. Cover launch and the one or two flows that earn money, and leave everything else to unit tests and previews.

Can previews use real network data?

They can, but they should not. Apple's WWDC19 session advises avoiding network calls in previews and loading sample data from a Preview Assets catalog, which keeps previews fast and repeatable.

Related services