LAST CHANCE: Save 50% on all my Swift books and bundles! >>


Found 8 articles in the Swift Knowledge Base for this category.


How to benchmark app launch time using XCTOSSignpostMetric.applicationLaunch

Optimizing your application’s launch time helps ensure users spend more time using your app and less time staring at your launch screen, and helpfully Xcode comes with a built-in way to help us measure and monitor that time: XCTOSSignpostMetric.applicationLaunch.... Continue Reading >>

How to check and unwrap optionals in tests using XCTUnwrap()

When writing tests, it’s common to want to unwrap an optional before checking it for a particular value. XCTUnwrap() does exactly that for us: it attempts to unwrap the optional, but will throw an error (and thus fail the test) if the optional is nil.... Continue Reading >>

How to do conditional test tear down using addTeardownBlock()

All XCTestCase subclasses have access to setUp() and tearDown() instance methods, plus setUp() and tearDown() class methods for one-time setup and tear down. But sometimes you need to add conditional tear down code: if your test creates a resource that must be destroyed, you can add that as an additional tear down step using the addTeardownBlock() method.... Continue Reading >>

How to do one-time setup for your tests

When you create a default XCTestCase using Xcode you’ll get default setUp() and tearDown() methods like these:... Continue Reading >>

How to set baselines for your performance tests

All performance tests in Xcode can have baselines attached to them, which are stored results that you consider representative of your app’s performance as things stand. The baseline is useful because it gives Xcode a measuring point for all other changes you make: if you accidentally change your code so that it runs slower, Xcode will consider your performance test to be a failure.... Continue Reading >>

How to test asynchronous functions using expectation()

XCTestCase has the built-in ability to work with asynchronous code using a system of expectations. First, you create one of more instances of XCTestExpectation using the expectation() method, then you run your asynchronous code, and finally you call waitForExpectations() so the test doesn’t end prematurely. ... Continue Reading >>

How to test throwing functions

One of the many brilliant features of Swift’s error handling system is its ability to throw errors during tests and have them considered as failures. That is, if you mark your test using throws you run any throwing code inside that test and if it throws an error the test will be marked as a failure.... Continue Reading >>

How to write performance tests using measure()

Performance tests let you check how fast your code runs, but more importantly it lets you check how fast your code runs over time – you can spot performance changes as your code evolves.... Continue Reading >>

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions, all written for Swift.

Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.