Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's import a new testing approach in Swift

Let's import a new testing approach in Swift

Nicolas Garcia

June 07, 2024
Tweet

More Decks by Nicolas Garcia

Other Decks in Programming

Transcript

  1. September 2023 New testing library announced in the Swift forums

    • https://forums.swift.org/t/a-new- approach-to-testing-in-swift/67425 • A rich thread of more than 100 comments, sharing thoughts and experiences with the community • New forum category: https:// forums.swift.org/tag/swift-testing
  2. Who am I iOS Developer Consultant • Back to early

    2013 • A fi rst experience with Eclipse IDE and Android SDK • Xcode 4.6 and an iPhone 4 • I’m sorry for those of you coming from the pre-ARC era 🦕 • Worked on IoT, video, banking and Cloud
  3. A decade of iOS development We’ve witnessed so many changes

    • iOS 6: UIKit’s AutoLayout and the iPhone 5 • iOS 7: From skeuomorphic to fl at design • iOS 8: Hello Swift ! • iOS 13: Hello SwiftUI, and hello to you Combine as well • iOS 15: Swift Concurrency • iOS 17: Swift 5.8 - Macros
  4. Oldies but goodies XCTest has received some love over the

    past decade • 2015: XCTestExpectation and and performance testing APIs: measureBlock {} • 2016: XCTAttachment • 2017: XCTContext.runActivity(named:block:) • 2019: XCTOSSignpostMetric for performance measuring • 2020: XCTAttachment(screenshot: ... ) • 2021: XCTMeasureOptions • 2022: XCTSkip • 2023: Hello XCTWaiter • Performance measuring • Attaching metadata • Test availability • Concurrency
  5. Vision for a modern Swift Testing API 4 principles •

    Approachability • Expressivity • Flexibility • Scalability • https://github.com/apple/swift-testing/blob/main/Documentation/Vision.md
  6. import Testing Key points • Xcode/SPM Integration state • @Test

    and @Suite • #expected and #required • Traits
  7. import Testing @Test and @Suite • Flexible test organisation •

    Free standing global functions • Enclosing type acting as a test suite • Bye “test” pre fi x • Bye var myDependency: IWO! • Parameterized tests (N*M or zipping collections)
  8. import Testing Test Traits • Traits are a variadic parameter…

    • Test availability at build time and run time • Time limit, measured in minutes • If applied to a @Suite, behaviour inherited to enclosed tests functions • If applied to a parameterized test, behaviour inherited to all test cases (each invocation separately)
  9. import Testing Test Traits • Comment, conforms to ExpressiblebyStringLiteral •

    Tag, strongly typed to be even shared between test targets • Bug, aiming to work with bug report solutions • Yes, there’s a Bug in the type system now… (pun intended) • https://github.com/apple/swift-testing/blob/main/Sources/Testing/Traits/Bug.swift#L18 • Not to be confused with the Issue type, which seems to be internally used to collect information about failing tests
  10. import Testing WWDC 2024, we want feature parity! • System

    integration: SPM and Xcode. • XCTestSca ff old already deprecated • Performance measurement • UI tests
  11. Nicolás García Let’s import a modern testing approach in Swift

    Thank you ! Feel free to connect on LinkedIn