iOS Integration Testing

A framework for integration testing iOS by simulating user interaction.

Written by Eric Firestone.

We love iOS for the fast and versatile experience it offers. But what we think is really cool is that it brings these attributes to the development process as well. The App Store makes short release cycles easy, allowing developers to address feedback quickly and add new features regularly. This improvement over the traditional box software model makes the agile development model a great choice, except for one thing: agile development requires good automated testing. We looked around and none of the existing iOS testing frameworks fit our needs, so we innovated.

Today we’re happy to announce KIF, the “Keep It Functional” framework. KIF allows for realistic iOS integration testing through simulated user interaction. We developed KIF to meet a few goals:

  • KIF requires minimal setup to run a test suite

  • KIF lets you develop your tests in the same language as the rest of your code to minimize learning and adaptation layers

  • KIF can be easily extended to fit your needs

  • KIF works in continuous integration (CI) setups

The resulting framework links completely into your app, and allows you to run tests in either the simulator or on the device. After configuring your Xcode project, running your KIF suite can be done easily because it has no external dependencies. To cover the majority of testing needs, KIF comes with a number of factory test steps built in, such as “tap this view,” “turn on this switch,” or “type this text.” These steps traverse the view stack using the built in accessibility capabilities of iOS. Making your app accessible is easy, and has the added advantage of making it navigable to your users with visual impairments.

If your testing requires more complex steps, KIF is ready for you. Because KIF links into your app and is written in Objective-C, you can easily add new steps, such as “simulate a memory warning,” “receive a push notification,” or even “fake the key combination up, up, down, down, left, right… from the plugged in game controller.” If the user can do it with your app, then KIF can do it, too. The demo video below shows KIF running a few sample payments with the Square app:

https://s3.amazonaws.com/square-production/video/kif-tests.mp4

To give you an idea of what a scenario in KIF looks like in code, here’s an example:

+ (**id**)**scenarioToLogIn**;
{
    KIFTestScenario *****scenario **=** [KIFTestScenario scenarioWithDescription:@"Test that a user can successfully log in."];
    [scenario addStep:[KIFTestStep stepToEnterText:@"[email protected]" intoViewWithAccessibilityLabel:@"Login User Name"]];
    [scenario addStep:[KIFTestStep stepToEnterText:@"thisismypassword" intoViewWithAccessibilityLabel:@"Login Password"]];
    [scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Log In"]];

    // Verify that the login succeeded
    [scenario addStep:[KIFTestStep stepToWaitForTappableViewWithAccessibilityLabel:@"Welcome"]];

    return scenario;
}

Finally, with the help of WaxSim, KIF runs in continuous integration, so you can get constant feedback about the health of your codebase.

We’re making KIF available as open source on GitHub, and more information is available in the embedded README. We’ve found KIF really useful, and we hope you do too. Check it out, and let us know what you think. There is a discussion groupavailable, or use the tag “kif-framework” on Stack Overflow. Eric Firestone (@firetweet) | Twitter *The latest Tweets from Eric Firestone (@firetweet): "Congrats @segiddins and @CocoaPods team for reaching the 1.0…*twitter.com