Last updated 3 months ago
Was this helpful?
附錄 ⟩ Testing System
XCTest:Swift 和 Objective-C 專案中常用的單元測試框架。
Swift Testing:現代化測試框架,Swift Package Manager 推薦選項。
Xcode ⟩ Product ⟩ Test (command + U) 可以執行所有測試 (Unit Tests)
If you choose to add tests to your project, Xcode will create two additional targets: one for unit tests and one for UI tests.
structure for a test case:
Arrange: arrange the "system under test" (SUT) and the "inputs".
Act: act on the SUT to get the "output".
Assert: assert the "output" matches the "expected result".
func testEmptyMenuReturnsEmptySections() { // ⭐️ Arrange: (arrange inputs) let menu = [MenuItem]() // ⭐️ Act: (generate output) let sections = menu.groupedByCategory() // ⭐️ Assert: (assert match) XCTAssertTrue(sections.isEmpty) }
Test-Driven Development in Swift (2021)
Test-Driven iOS Development with Swift - Fourth Edition
KHAWER ⟩ Unit Testing and UI Testing in Swift