A SwiftMonkey tutorial

How can we create better UI tests?

Prerequisites:

  • Some knowledge of CocoaPods in order to install SwiftMonkey

Terminology

UITests: Testing by interacting and validating the behaviour of UI elements

Background

The examples below use a simple setup of SwiftMonkey to help those not familiar with it. There’s even code in the git repo to help you out!

Tutorial

Create a new Single View project

$ pod init

$ vim podfile

Add the following to the pod file:

target ‘SwiftMonkeyTutorial’ do

pod “SwiftMonkeyPaws”, ‘~> 2.1.0’

end

target ‘SwiftMonkeyTutorialTests” do

pod ‘SwiftMonkey’, ‘~> 2.1.0’

end

target ‘SwiftMonkeyTutorialUITests” do

pod ‘SwiftMonkey’, ‘~> 2.1.0’

end

$ pod install

Update the AppDelegate

Update the UITests

if there are command line arguments containing “ — MonkeyPaws” we will see fun hands being placed on the UI when the tests are run:

Within the tests there are two options:

monkey.addDefaultXCTestPrivateActions()

and

monkey.addDefaultUIAutomationActions()

The second of which seemed to work for me on the simulator, and the first did not appear to work at all (The instructions say to pick one of the two).

This makes the complete test:

Want to get in contact? Try the link here:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store