Testing interview questions
46 questions from real iOS interviews. Topics: XCTest, Swift Testing, mocking, snapshots, UI tests, CI.
- TestingShort answer
Why unit tests
A teammate says they'd rather build one more feature than spend the time writing tests. How would you make the case for unit tests?
#unit-test #xctest #why-test #regression
- TestingMultiple choice
XCTest discovery rules
Which conditions does a method need before XCTest recognizes and runs it as a test? Select all that apply.
#xctest #xctestcase #test-discovery
- TestingShort answer
Test types and the pyramid
What's the difference between unit tests, integration tests, and UI tests?
#unit-test #integration-test #ui-test #test-pyramid
- TestingMultiple choice
Telling test doubles apart
"I want to replace the analytics event sender and check in the test which events the view model sent, with which arguments, and how many times." Which test dou…
#test-double #spy #stub #mock
- TestingMultiple choice
@testable import
When the test target does @testable import MyApp, which declarations become accessible?
#testable #access-control #test-target
- TestingShort answerPandorainterview report
Testing a playlist view model
A music app's playlist ViewModel takes a track list from a Repository and produces loading, success, and error states. How would you test those state transitio…
#unit-test #fake #viewmodel #state
- TestingShort answer
Arrange-Act-Assert
Why do you split test code into Arrange-Act-Assert (Given-When-Then)?
#aaa #given-when-then #tdd #red-green-refactor
- TestingShort answer
Test doubles
What is a test double?
#test-double #mock #stub #fake
- TestingShort answer
Testing an API-backed screen
This screen leans heavily on an API response. How would you change the code so you can test the screen, view model included, without a server request?
#view-model #dependency-injection #stub #mvvm
- TestingShort answer
Testing private methods
A private method inside a custom view holds complicated calculation logic and you want to test it. How would you test that private method, or should you leave …
#private #testable #encapsulation #custom-view
- TestingShort answer
Testing async code
How do you test an async/await API in a unit test?
#async #xctestexpectation #async-await #swift-testing
- TestingMultiple choice
XCTest lifecycle
In the XCTestCase below, which order are the calls made in when testA and testB run? …
#xctest #setup #teardown #lifecycle
- TestingMultiple choice
Code coverage
Which statements about code coverage are correct? Select all that apply.
#coverage #xcode #metrics
- TestingShort answer
Testing a view model
If you were testing load() on the view model below, which cases would you verify? …
#mvvm #view-model #observation #state
- TestingMultiple choice
Swift Testing macros
Which statements about Swift Testing's #expect and #require are correct? Select all that apply.
#swift-testing #expect #require #macros
- TestingShort answerX (Twitter)
Tests in a take-home
You got a take-home for a minimal iOS app with basic unit tests, and the brief says to finish in three to five hours. With time that tight, where would you put…
#take-home #unit-test #prioritization #architecture
- TestingShort answerHeadspace
Tests in the workflow
This is a written question on a take-home: "how do you integrate tests into your development workflow?" Walk me through when and how tests run, from the moment…
#workflow #ci #pull-request #test-plan
- TestingMultiple choiceApple
Testing a data structure
On CoderPad you're asked to implement a MaxStack where push, pop, top, and max are all O(1), built on a Swift protocol, and verify it with XCTest. Which are ap…
#xctest #test-design #edge-case #coderpad
- TestingShort answerDeliveroo
Reviewing an iOS PR
A take-home asks you to review an existing PR and leave comments. When you review an iOS PR, what do you look at and in what order?
#code-review #pull-request #quality #take-home
- TestingShort answer토스interview report
Writing testable code
The question asks about your experience writing code with unit tests in mind and the philosophy you took from it. Give me the principles you hold to as concret…
#testability #dependency-injection #pure-function #design
- TestingMultiple choice카카오뱅크interview report
Quick and Nimble
Your team's codebase uses Quick and Nimble. Which statements about the two libraries are correct? Select all that apply.
#quick #nimble #bdd #xctest
- TestingShort answerBarclaysinterview report
Reading coverage
An iOS payment app has 90% line coverage, yet payment failure handling regresses every release. What does that 90% guarantee, and what does it fail to guarante…
#testing #coverage #risk #unit-test
- TestingShort answer요기요interview report
Trustworthy tests on CI
In a delivery app's iOS project the unit tests and UI tests pass locally but fail now and then only on CI. How would you cut down these flaky tests?
#ci #flaky-test #fixture #test-plan
- TestingShort answer마이리얼트립interview report
Scope of UI tests
A travel booking app's search screen UI tests call every API against the real server, so they're slow and break often. How would you split what stays a UI test…
#ui-test #stub #launch-arguments #testing-pyramid
- TestingShort answer클래스101interview report
The first TDD test
You're adding coupon discount pricing rules to an online course app with TDD. In the red-green-refactor cycle, which example would you pick as the first test?
#tdd #red-green-refactor #unit-test #refactoring
- TestingShort answerSOOPinterview report
Testing an async stream
A live streaming app's chat ViewModel subscribes to incoming messages as an AsyncSequence and appends them to a list. How would you control that message stream…
#asyncstream #testing #cancellation #realtime
- TestingShort answer강남언니interview report
Regression tests in review
A PR fixing a bug in a beauty appointment app got a review comment saying there's no reproduction test. The reviewer has already read the code and could approv…
#code-review #regression #behavior #testing
- TestingShort answer번개장터interview report
Layers of test automation
You're adding automated tests to the listing feature of a secondhand marketplace app for the first time. What would you put on each of the three layers: unit t…
#test-pyramid #ci #automation #quality
- TestingShort answer
Mocking the network
You want to test a network layer that uses URLSession directly, with no real server. Can you give me at least two ways to do it?
#urlsession #urlprotocol #mock #network
- TestingShort answer
Replacing UI tests
You have dozens of UI tests that are slow and break often. How would you restructure the code and the tests to replace most of them with unit tests?
#ui-test #unit-test #presentation-logic #snapshot
- TestingMultiple choice
Flaky tests
Which of the following cause flaky tests that fail only sometimes on CI? Select all that apply.
#flaky #determinism #shared-state #test-isolation
- TestingShort answer
Testing Core Data and SwiftData
How do you set up unit tests for a store layer that depends on Core Data (or SwiftData) so that nothing is left on disk?
#core-data #swiftdata #in-memory #persistence-test
- TestingShort answer
Swift Testing against XCTest
How is Swift Testing different from XCTest?
#swift-testing #xctest #migration #macros
- TestingShort answer
Snapshot testing
You want to introduce snapshot testing to your team. What problem does snapshot testing solve?
#snapshot-test #visual-regression #swift-snapshot-testing #ci
- TestingShort answer
Stabilizing UI tests
A login flow test written in XCUITest fails about 30% of the time on CI. What would you change on the app side to stabilize it?
#xcuitest #accessibility-identifier #launch-arguments #flaky
- TestingMultiple choice
Testing time-dependent code
The "retry after three seconds" logic uses Task.sleep(for: .seconds(3)), so the test really waits three seconds each time. Which are correct approaches for mak…
#clock #time #task-sleep #determinism
- TestingShort answerGojek
TDD on an existing project
This one comes up onsite: "how does your team use tests today, and how would you follow TDD on a real project?" Answer it around a realistic way to bring TDD i…
#tdd #legacy #coverage #ui-test
- TestingShort answerWalmart
Unit testing around a singleton
An app calls AuthManager.shared directly all over the code. How would you unit test the code that depends on this singleton? …
#singleton #dependency-injection #test-isolation #protocol
- TestingShort answerDiscord
Architecture that invites tests
One item the architecture round scores is "can you add unit tests without a big refactor". Which design decisions satisfy that condition, with an example?
#architecture #testability #dependency-injection #design-round
- TestingShort answerCRED
What's worth testing
You just built a product list screen in a live coding round: view model, network, price formatting, and a favorite toggle. The interviewer asks, "on this scree…
#test-strategy #what-to-test #cost-benefit #priority
- TestingMultiple choiceFlipkart
URLProtocol-based mocking
To test the network layer you've decided to intercept responses with a URLProtocol subclass. Which statements are correct? Select all that apply. …
#urlprotocol #mocking #urlsession #network-test
- TestingShort answer센드버드interview report
Testing an SDK
Say you're building a chat SDK that ships inside other companies' apps rather than an app of your own. From a testing point of view, what changes compared with…
#sdk #integration-test #contract-test #backward-compatibility
- TestingMultiple choice
Swift Testing execution model
In a suite written with Swift Testing, several tests write to and read from the same file path and fail intermittently. What's the most fundamental fix?
#swift-testing #parallel #serialized #shared-state
- TestingShort answer
Testing concurrent code
How do you reproduce or detect a data race in concurrent code that uses actors and Tasks?
#actor #sendable #data-race #thread-sanitizer
- TestingShort answer
Test strategy at scale
An app with 40 modules and 8,000 tests takes 40 minutes of CI tests. How would you change the test structure and the run strategy to get each PR under 10 minut…
#test-plan #modularization #ci #parallel
- TestingMultiple choice
XCTestCase instance lifecycle
Which are problems with the test class below? Select all that apply. …
#xctest #lifecycle #memory #setup