XCTest basics (targets, fixtures)
Set up XCTest targets in Swift packages or Xcode projects, write test cases, and manage fixtures with setUp / tearDown .
XCTest intro
Swift uses XCTest for unit testing. Create a test target, subclass XCTestCase, and write methods starting with test.
Basic test method
A test case is a subclass of XCTestCase. Each test method must start with test and use assertions.
import XCTest
final class MathTests: XCTestCase {
func testAdd() {
XCTAssertEqual(2 + 2, 4)
}
}All lessons in this course
- XCTest basics (targets, fixtures)
- Logging, assert/precondition/fatalError