Test-Driven iOS: Testing Asynchronous Network Calls with FutureKit

Lately I’ve found myself writing asynchronous network calls on mobile platforms in the reactive style. I want to share how you can test-drive calls like this for iOS. The following example uses SwiftyJSON for JSON deseriaization and FutureKit as the asynchronous framework surrounding the network call. There are several libraries in iOS that do both of these things, but your structure here will look similar with any of them.

This example is updated to Swift 3.

Continue reading “Test-Driven iOS: Testing Asynchronous Network Calls with FutureKit”

Test-Driven iOS: Mocking Dependencies

Once upon a time we talked about how to initialize and launch view controllers manually. We did that so we could inject our dependencies via the initializer, then unit test our view controllers independently of those components.

Then we talked about how you can inject dependencies while loading your view controllers from the storyboard, instead of manually instantiating them.

We isolate the system under test from its dependencies by using  faked versions of those dependencies.

Today, we’ll look at a fake in more detail for unit testing your iOS app.

Continue reading “Test-Driven iOS: Mocking Dependencies”

Test-Driven iOS: Introduction to Feature Tests

In past articles about test-driven iOS, I have talked about how to resolve some challenges of unit testing an iOS app. This time I’ll talk about higher level tests that validate how the view looks and behaves when users interact with it (UI tests) as well as the app’s API requests and response handling (integration tests).

A feature test validates both the UI and the API calls of an app to document how a feature should work.

Today we’ll look at an example feature test in Swift. I’ll start by explaining the structure and purpose of feature tests, but you can skip to the code if you prefer.

Continue reading “Test-Driven iOS: Introduction to Feature Tests”

Test-Driven iOS: Testing an App with Storyboard UI

In this post a while back, I mentioned two options for setting up unit test-friendly dependency injection in an iOS app: dependency injection libraries and constructor injection with code-defined views. In that piece, I talked about using a code-only UI to achieve my testing goals.

Since then, I have learned a few more strategies that allow me to unit test my iOS apps while still defining the views through the storyboard, as Apple intended. Here I’ll share some of what that looks like with you.

Continue reading “Test-Driven iOS: Testing an App with Storyboard UI”

Test-Driven iOS: Enabling Unit Testing with a Code-Only UI

I write automated unit tests for each of the classes inside my apps. This includes iOS apps, which have classes that extend classes defined by the iOS framework. I want these classes to take care of the framework-specific and device-specific details of showing new screens, handling their life cycles, et cetera. For other logic that I write, I like to have my view controllers and other iOS objects delegate that work to injected classes.

Continue reading “Test-Driven iOS: Enabling Unit Testing with a Code-Only UI”

Blog at WordPress.com.

Up ↑