Slide 1

Slide 1 text

Nicolás García Let’s import a modern testing approach in Swift

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Fast-forward to September 2023

Slide 7

Slide 7 text

Vision for a modern Swift Testing API 4 principles • Approachability • Expressivity • Flexibility • Scalability • https://github.com/apple/swift-testing/blob/main/Documentation/Vision.md

Slide 8

Slide 8 text

Let’s import a modern testing approach in Swift

Slide 9

Slide 9 text

Let’s import a modern testing approach in Swift

Slide 10

Slide 10 text

Hello, 
 import Testing

Slide 11

Slide 11 text

import Testing Key points • Xcode/SPM Integration state • @Test and @Suite • #expected and #required • Traits

Slide 12

Slide 12 text

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)

Slide 13

Slide 13 text

import Testing XCTest assertion migration chart

Slide 14

Slide 14 text

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)

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

import Testing WWDC 2024, we want feature parity! • System integration: SPM and Xcode. • XCTestSca ff old already deprecated • Performance measurement • UI tests

Slide 17

Slide 17 text

import Testing WWDC 2024, we want feature parity!

Slide 18

Slide 18 text

Nicolás García Let’s import a modern testing approach in Swift Thank you ! Feel free to connect on LinkedIn