Swift Quality Control & Assurance 2 — Questions and Answers
Question 1: In Swift, which testing framework is natively included with Xcode for unit testing?
- Quick
- Nimble
- XCTest (Correct answer)
- SpecKit
Correct answer: XCTest
XCTest is Apple's native testing framework bundled with Xcode for writing and running unit, performance, and UI tests in Swift.
Question 2: Which assertion in XCTest verifies that two values are NOT equal?
- XCTAssertFalse
- XCTAssertNil
- XCTAssertNotEqual (Correct answer)
- XCTAssertThrows
Correct answer: XCTAssertNotEqual
XCTAssertNotEqual checks that two given values are not equal, failing the test if they are.
Question 3: What does 'code coverage' measure in Swift quality assurance?
- The number of test files in the project
- The percentage of source code lines executed during tests (Correct answer)
- The speed at which tests run
- The number of passing assertions
Correct answer: The percentage of source code lines executed during tests
Code coverage measures what percentage of your source code lines are actually executed when your test suite runs.
Question 4: In a Swift project, what is the purpose of a 'test target' separate from the main app target?
- To compile a release build of the app
- To isolate test code so it doesn't ship with production code (Correct answer)
- To generate documentation automatically
- To manage app signing certificates
Correct answer: To isolate test code so it doesn't ship with production code
A separate test target keeps test code out of the production binary, ensuring tests only run in the development/CI environment.
Question 5: Which Swift quality practice involves writing tests BEFORE writing the implementation code?
- Behavior-driven development
- Test-driven development (TDD) (Correct answer)
- Integration testing
- Smoke testing
Correct answer: Test-driven development (TDD)
Test-driven development (TDD) follows a red-green-refactor cycle where tests are written first to define expected behavior.
Question 6: What does 'XCTAssertThrowsError' verify in a Swift unit test?
- That a function returns a non-nil value
- That a closure executes without throwing
- That a closure throws an error when called (Correct answer)
- That two objects share the same memory address
Correct answer: That a closure throws an error when called
XCTAssertThrowsError passes the test when the provided closure throws an error, confirming expected error-throwing behavior.
Question 7: In continuous integration (CI) for Swift projects, what typically triggers an automated test run?
- Manually opening Xcode
- Pushing code changes to a version control repository (Correct answer)
- Installing a new Xcode version
- Archiving the app for distribution
Correct answer: Pushing code changes to a version control repository
CI pipelines are configured to automatically run tests whenever code is pushed or a pull request is opened in the repository.
In Swift, which testing framework is natively included with Xcode for unit testing?