Swift Quality Control & Assurance 3 — Questions and Answers
Question 1: What type of testing validates that different modules or services in a Swift app work correctly together?
- Unit testing
- Integration testing (Correct answer)
- Snapshot testing
- Load testing
Correct answer: Integration testing
Integration testing validates the interaction between multiple components, modules, or services rather than testing them in isolation.
Question 2: In Swift UI testing with XCTest, which class is used to represent and interact with the running application?
- XCUIElement
- XCUIApplication (Correct answer)
- XCTestCase
- XCUIScreen
Correct answer: XCUIApplication
XCUIApplication represents the app under test and provides methods to launch, terminate, and interact with it during UI tests.
Question 3: What is a 'mock object' used for in Swift unit testing?
- To generate random test data automatically
- To replace a real dependency with a controlled substitute (Correct answer)
- To measure test execution performance
- To simulate network traffic at scale
Correct answer: To replace a real dependency with a controlled substitute
Mock objects replace real dependencies with controlled substitutes so tests can verify interactions without relying on external systems.
Question 4: Which Xcode feature visually highlights which lines of code are covered or missed by your tests?
- Instruments Time Profiler
- Code coverage gutters in the source editor (Correct answer)
- Address Sanitizer
- Build analyzer
Correct answer: Code coverage gutters in the source editor
Xcode's code coverage gutters display colored indicators next to each line showing whether it was executed during test runs.
Question 5: What does 'flaky test' mean in Swift quality assurance?
- A test that always fails
- A test that passes and fails intermittently without code changes (Correct answer)
- A test that takes too long to run
- A test with no assertions
Correct answer: A test that passes and fails intermittently without code changes
A flaky test is one that produces inconsistent results — sometimes passing, sometimes failing — without any changes to the underlying code.
Question 6: In XCTest performance testing, what does 'measure {}' do?
- Counts the number of objects allocated in a block
- Runs the block multiple times and records execution time metrics (Correct answer)
- Checks memory leaks in the enclosed code
- Validates thread safety of the block
Correct answer: Runs the block multiple times and records execution time metrics
The measure block runs its contents multiple times (typically 10 iterations) and records timing metrics to detect performance regressions.
Question 7: Which Swift tool analyzes code for potential bugs and quality issues WITHOUT running the code?
- XCTest
- Instruments
- Static analyzer (Analyze in Xcode) (Correct answer)
- Address Sanitizer
Correct answer: Static analyzer (Analyze in Xcode)
Xcode's static analyzer inspects code paths at compile time without executing the program, finding issues like memory leaks and logic errors.
What type of testing validates that different modules or services in a Swift app work correctly together?