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”

Material Design: An Experience Report by Andy Detskas

Today at lunch at Pivotal Labs, our designer Andy Detskas talked with us about some of the things he has learned about material design for Android Marshmallow.

If you’d like to see more details on the presentation than the rundown provided here, or if you’d like to follow some links to useful resources on designing for Android, you can see the slides right here.

Continue reading “Material Design: An Experience Report by Andy Detskas”

Test-Driven Android: Tab Layouts

Tab layouts indicate that there are multiple pages to look at, and users can swipe them or click them to move from page to page.

tabs

Their implementation makes them difficult to test drive, so in this post we will go over how to do it.

We implement the tabs in Android by placing a TabLayout element in our activity’s view, then getting ahold of it in the Activity class code and adding tabs to it. There are limited ways to get an instance of TabLayout.Tab, and because it is a final class, it cannot be mocked.

Continue reading “Test-Driven Android: Tab Layouts”

Blog at WordPress.com.

Up ↑