Test-Driven iOS: Passing Information With Segues

In past posts of test-driven iOS, we have talked about instantiating view controllers with dependencies. What if we want to pass information from one view controller to the next one?

Let’s explore how we would test-drive a storyboarded iOS application that passes information from a master list view controller to a detail view controller.

Continue reading “Test-Driven iOS: Passing Information With Segues”

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: Using Segues

When we build storyboards in iOS to wireframe and illustrate the flow of our apps, we can use segues to create transitions between screens and their elements. But if we want to unit test those transitions, we have to do it differently than we would if we were manhandling the transition programmatically with presentViewController().

So how do we do it? With three steps.

Continue reading “Test-Driven iOS: Using Segues”

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”