Getting Started With KIF for Functional iOS UI Testing
Let's take a look at what KIF has to offer for UI test automation and how to get started with it.
Join the DZone community and get the full member experience.Join For Free
Since the deprecation of UI Automation from the latest Xcode there has been lots of buzz around XCTest and XCUITest. These frameworks have served many of you since Xcode 5 and many of you have used frameworks that are build on top of XCTest implementation. KIF – Keep It Functional – is a great example of those frameworks.
In this blog, we’ll take a look at what KIF has to offer for UI test automation and how to get started with it.
Bitbar Public Cloud Product Update
With the December release (22nd of December 2016), KIF support was enabled for Bitbar Public Cloud users. With the support of XCTest project type in Public Cloud, it’s now possible to also execute KIF tests in Public Cloud and the same support has been available for Private Cloud and On-Premise solutions for some time already.
There are questions every now and then why should you use KIF as there are plenty of other frameworks available and nevertheless it is tightly integrated with XCTest. Are there any benefits of using KIF over the regular XCTest for iOS app testing? We’ll take a look at it in this blog.
Introduction to KIF iOS Integration Testing Framework
KIF (short for “keep it functional”) is an iOS integration test framework that is closely related to and that uses XCTest test targets. KIF tests can be executed directly in
XCTestCase or any subclass. KIF allows for easy automation of iOS applications by leveraging the accessibility attributes that the OS makes available to those with visual disabilities.
One of those things why KIF has got some popularity among iOS developers is that it performs those tests using standard Xcode test targets and all tests can be written using Objective-C or Swift as normal XCTest subclasses.
Features and Benefits of KIF
Easy to Learn – No Real Learning Curve
As Swift and Objective-C are the options for iOS app developers to use, KIF is very easy to use in Swift and Objective-C based projects and it supports apps written either with Swift or Objective-C. This basically limits the complexity that typically comes from the test setups where several languages are used.
KIF integrates directly to Xcode project and there is no need to install any packages, set up additional servers, or integrate with any other instances.
Support for Various iOS Versions
Since XCTest was introduced in Xcode, iOS have seen several major (and minor) releases after that. However, XCTest has remained consistent test option for iOS app developers and OS version fragmentation hasn’t have too much impact on how it can be used for test automation. Basically KIF supports even older iOS versions and from the user point of view changes required to get things running are minimalistic (all related to Xcode).
User-like Test Automation
KIF among the other frameworks provide user-like inputs and all events and interactions for automation are similar of how an actual user would use the app under test. In addition, XCTest/XCUITest foundation provides great API to variety of different user interactions, clicks and even gestures. The basic selection of gesture and interaction API includes:
func tap() func doubleTap() func twoFingerTap() func tap(withNumberOfTaps: UInt, numberOfTouches: UInt) func press(forDuration: TimeInterval) func press(forDuration: TimeInterval, thenDragTo: XCUIElement) func swipeLeft() func swipeRight() func swipeUp() func swipeDown() func pinch(withScale: CGFloat, velocity: CGFloat) func rotate(CGFloat, withVelocity: CGFloat)
More information about XCTest elements can be found under Apple’s documentation.
Development Tool Compatibility
The only tool iOS developer needs to design, develop and test their iOS apps is the Xcode environment. KIF and XCTest are tightly integrated with it and for example Test Navigator, Bots and other Xcode features are readily available and handy to use with KIF tests.
How to Get Started with KIF
First of all, download the KIF source assets from GitHub and place it somewhere where you can easily find it. Alternatively, you can use Git’s submobule to get source code for your local use:
$ git init $ git submodule add https://github.com/kif-framework/KIF.git Folder/Here
NOTE! This needs to be added to your iOS project folder (=Folder/Here should be under your iOS project).
In order to install KIF, you’ll need to link the
libKIF static library directly to your app. Also, there is readily available example for Swift under KIF repository.
Working on Xcode
To use KIF with your iOS app you have now placed its project, source and test templates under your iOS project. You can also open
KIF.xcodeproj in Project Navigator and inspect the following files included with the installation:
MainStoryboard.storyboard open (under Test Host folder) and the following scene should be open and editable:
I’ll come back with more detailed article about storyboard use and how to get the best out of it, but for this one it’s a good advice to take a look what is included under “Master Scene” and “Navigation Controller Scene”. This should give you a basic info on how to work with storyboard features in Xcode.
Adding a new Testing Target
Depending on which Xcode you are using (and yes, we’re encouraging people to use the latest and greatest) creating a new test target can be done via different routes.
Under File -> New -> Target you can find the testing target wizard:
Configure the parameters and create a testing target (click Finish):
Now, you can configure your iOS project. First, click your project name on Project Navigator and you will see the “Build Phases” on the right side. Open “Link Binary With Libraries” and locate
libKIF.a and click Add. KIF will be now added to your project and library is linked as a binary with your app.
Finally, KIF requires IOKit so this can be added to your project under “Build Settings” -> Linking and “Other Linker Flags”. Just add “-framework IOKit” there as a parameter and all should be good:
Now, that’s the basic information to get you started with KIF. More detailed instruction on how to use KIF efficiently will be posted later.
Happy iOS Testing Folks!
Published at DZone with permission of Ville-Veikko Helppi, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Observability Architecture: Financial Payments Introduction
RBAC With API Gateway and Open Policy Agent (OPA)
How to LINQ Between Java and SQL With JPAStreamer
File Upload Security and Malware Protection