Unit Testing Dispatch Queues With Dependency Injection

September 30, 2018 | Swift, Networking, Unit Testing, iOS, macOS, tvOS, watchOS

We write asynchronous code when we know a task will take time to complete, whether because it's computationally expensive or we're making a network request. Testing this code can be difficult, especially when the asynchronous logic is internal. For example, let's say we're making a fire and forget request to load an image into an image view? We would likely make the request on a background queue and . . .

Making Views More Testable & Reusable

July 22, 2018 | Swift, Unit Testing, iOS, macOS, tvOS, watchOS

In this tutorial, we'll see how we can use protocols to make custom view subclasses more generic. The benefit is that they'll be easier to test and reuse, and our code will be easier to read and maintain.

Observing Real-Time Ouput From Shell Commands In A Swift Script

June 27, 2018 | Swift, Unit Testing, Scripting, iOS, macOS, tvOS, watchOS

In the last tutorial, we saw how to generate code coverage reports using the new `xccov` tool. Part of that process is using the `xcodebuild` command to build a project with code coverage enabled. We ran that command directly in Terminal, but we could also run `xcodebuild` in a Swift script. The problem is `xcodebuild` takes time, and . . .

xccov: Generating Code Coverage Reports

June 21, 2018 | Swift, Unit Testing, Scripting, iOS, macOS, tvOS, watchOS

With the release of Xcode 9.3, Apple included a new command line tool called "xccov". It can be used to view code coverage reports as JSON, which can then be used to automate code coverage workflows. In this tutorial we'll see how to generate and view code coverage reports. We'll then write a Swift script to process the report.