I’m pulling together some of the notes around iOS mobile testing that I’ve gleaned from research and interviews with TestTalks guests around mobile testing. Also picking an iOS testing framework is just the beginning so make sure to check out my post on how you can take the guessing out of you mobile testing coverage efforts.
Here are 7 iOS tools that seemed to be mentioned most (and that many people are using) that you need to know about for mobile automation testing. For the video version check [click here]
For unit testing, you can use the framework called XCTest. XCTest is provided by Apple and has pretty good integration with the IDE for writing your tests, running your tests and even doing TDD workflow.
If you performed any unit testing prior to iOS 6, you may have heard of a tool called OCUnit. OCUnit has now depreciated, and ever since Xcode 5, the recommended testing framework has been XCTest.
2. UI Automation
For your more typical functional tests (or black-box tests), in which you’re going to write code that simulates an end user navigating your app, there is UI Automation. UI Automation is provided by Apple and is the Apple-sanctioned way of performing iOS functional testing.
To use UI Automation you need to use Instruments, one of the tools that comes with Xcode.
UI Automation itself is pretty lightly documented. If you have problems using it, you’re kind of left up to trial and error. What’s even worse is that there’s is not much of a community around it that you can consult for support.
Also — when newer versions of XCODE are released Apple rarely, if ever, issues any new updates to UI Automation.
That’s kind of the state of testing in terms of what Apple provides.
If the Apple tools don’t meet your needs there are also a couple of pretty popular third party ways to test your iOS code that might actually work better for you.
I’m aware that many teams love and heavily use OCmock. It’s like your typical mock object framework, and it’s really good for stubbing out and making mock objects of stuff, like code that leverages in a remote API, like a web service.
You can also use it for code that relies on a UI being available, like UI objects that you can’t easily instantiate yourself through unit tests.
4. KIF (Keep It Functional)
A good alternative to UI Automation is a tool called KIF.
KIF stands for “Keep it Functional.” I like to refer to it as UI Automation ++.
It’s third party, and it’s open source.
You write tests much in the same way as UI Automation, where you’re simulating a user, tapping through the app.
Like UI Automation, it relies on accessibility labels; you define your application, which has the side benefit of making your app accessible to people who may be visually impaired that are being prompted through audio queues and how to use your app.
Basically UI Automation and KIF both rely on you defining accessibility labels on your UI elements in terms of how they navigate the app.
Additionally, the way KIF tests are executed in the same type of target that your unit tests are executed in, which is not the case for UI Automation.
In order to execute UI Automation tests, you have to use the other tool by Apple called Instruments (it’s also their profiler tool). It’s actually a great tool, but kind of like UI Automation that is tacked onto it.
As always your goal should always be to make your tests repeatable and quickly executable. By integrating with the same way that XCTest runs unit tests, KIF makes those kind of GUI- based tests much faster to execute.
FBSnapshotTestCase was created and is maintained by Facebook. Its basic function is that it allows you to verify your UI code by doing visual diffs between saved screenshots.
You can do it at a more granular level than the full screenshot of the device. You can pick a little UI view in what you subclass when you see a little widget on the screen; anything from a piece of text to something more complicated. You can also isolate that snapshot test case to that UI view subclass.
I definitely see some usefulness in that beyond the normal kind of simulated click and play you might get with UI Automation.
6. FRANK – BDD for iOS
If you want to do end-to-end testing in iOS and wish you could use BDD and Cucumber, no worries –there’s a tool called Frank that will allow you to create acceptance tests and requirements using Cucumber.
Frank gives you the ability to run your BDD tests against your iOS application since it acts like an adaptor that connects your app to Cucumber.
The Cucumber recipes book has a nice step-by-step recipe(28) called Test iOS Using Frank that is really helpful.
Appium is a free, open-source, cross-platform mobile UI automation framework. It allows you to write UI tests for your mobile apps, for Android iOS, and some other OSs. It also lets you write it using the Selenium JSON writer you know and love from web automation. Appium is becoming an industry standard for mobile testing, much as Selenium WebDriver become the industry standard for browser-based automation a few years ago. Check out my Appium Tutorial for Beginners for more info on Appium.
Mobile Automation Awesomeness for Your Earbuds
I highly recommend that you not only learn more about these tools, but heed the advice of engineers who have successfully used these tools to automate their own projects in the real world. Check out: