• This repository has been archived on 05/Dec/2022
  • Stars
    star
    1,945
  • Rank 22,826 (Top 0.5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A framework for doing randomised UI testing of iOS apps

SwiftMonkey

This project is a framework for generating randomised user input in iOS apps. This kind of monkey testing is useful for stress-testing apps and finding rare crashes.

It also contains a related framework called SwiftMonkeyPaws, which provides visualisation of the generated events. This greatly increases the usefulness of your randomised testing, as you can see what touches caused any crash you may encounter.

Why Use SwiftMonkey?

  • When testing your UI, it's very easy to think about how to test how things should work, but do you struggle to figure out what kind of thing might not work?
  • Ever showed your app to someone who proceeded to bang away at the screen and immediately crashed it by doing something you had never thought of?
  • Do you want to feel a bit more confident about your app's stability?
  • Do you have rare crashes that you just can't reproduce?
  • Do you have memory leaks that take a long time to manifest themselves, and require lots of UI actions?

Randomised testing will help you with all of these!

SwiftMonkey is inspired by and has similar goals to UI AutoMonkey, but is integrated into the Xcode UI testing framework, providing better opportunities to debug.

Also, it is fun to look at:

Quick Start

To see for yourself how this framework works, just grab the code and open SwiftMonkeyExample/SwiftMonkeyExample.xcodeproj. Then press Cmd-U to run the UI test.

Installation

As a high-level overview, add SwiftMonkey.framework to your UI test target. Then add a test that creates a Monkey object and uses it to generate events.

Optionally, you also add the SwiftMonkeyPaws.framework to your main app, and create a MonkeyPaws object to enable visualisation. You probably only want to do this for debug builds, or when a specific command line flag is used.

Requirements

SwiftMonkey uses Swift 4.0. It has no dependencies other than iOS itself (8.0 and up should work). SwiftMonkeyPaws doesn't have any dependencies, either; you can even use on its own, without SwiftMonkey.

CocoaPods

You can install the frameworks using CocoaPods. Assuming that you've named your main app and test targets "App" and "Tests", you can use something like this in your Podfile:

target 'App' do
    pod 'SwiftMonkeyPaws', '~> 2.1.0'
end

target 'Tests' do
    pod 'SwiftMonkey', '~> 2.1.0'
end

Manual Installation

Copy the SwiftMonkey and SwiftMonkeyPaws folders into your project. Next, drag the xcodeproj files into your project.

Then, for SwiftMonkey, add SwiftMonkey.framework as a dependency for your test target, and add a Copy Files build phase to copy it into Frameworks.

For SwiftMonkeyPaws, adding SwiftMonkeyPaws.framework to the Embedded Binaries section of your app target is enough.

(You can also just directly link the Swift files, if you do not want to use frameworks.)

Swift Package Manager

As of this writing, the Swift Package Manager doesn't support iOS projects. SPM package files have experimentally been created, but obviously don't really work yet.

Usage

SwiftMonkey

To do monkey testing, import SwiftMonkey, then create a new test case that uses the Monkey object to configure and run the input event generation. Here is a simple example:

func testMonkey() {
        let application = XCUIApplication()

        // Initialise the monkey tester with the current device
        // frame. Giving an explicit seed will make it generate
        // the same sequence of events on each run, and leaving it
        // out will generate a new sequence on each run.
        let monkey = Monkey(frame: application.frame)
        //let monkey = Monkey(seed: 123, frame: application.frame)

        // Add actions for the monkey to perform. We just use a
        // default set of actions for this, which is usually enough.
        // Use either one of these but maybe not both.

        // XCTest private actions seem to work better at the moment.
        // before Xcode 10.1, you can use
        // monkey.addDefaultXCTestPrivateActions()

        // after Xcode 10.1 We can only use public API
        monkey.addDefaultXCTestPublicActions()

        // UIAutomation actions seem to work only on the simulator.
        //monkey.addDefaultUIAutomationActions()

        // Occasionally, use the regular XCTest functionality
        // to check if an alert is shown, and click a random
        // button on it.
        monkey.addXCTestTapAlertAction(interval: 100, application: application)

        // Run the monkey test indefinitely.
        monkey.monkeyAround()
}

The Monkey object allows you not only to add the built-in event generators, but also any block of your own to be executed either randomly or at set intervals. In these blocks you can do whatever you want, including (but not only) generate more input events.

Documentation for this is limited at the moment, so please refer to Monkey.swift and its extensions for examples of how to use the more advanced functionality if you need it.

SwiftMonkeyPaws

The simplest way to enable the visualisation in your app is to first import SwiftMonkeyPaws, then do the following somewhere early on in your program execution:

var paws: MonkeyPaws?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    if CommandLine.arguments.contains("--MonkeyPaws") {
        paws = MonkeyPaws(view: window!)
    }
    return true
}

(This example uses application(_, didFinishLaunchingWithOptions), but any time after you have a UIWindow will do. It also only instatiates the visualisation if a certain command line flag is passed, so that it can be enabled only for test runs.)

Using command line flags, If you want to enable MonkeyPaws on your test case file you can add the following on yout testMonkey function:

  let application = XCUIApplication()
  application.launchArguments = ["--MonkeyPaws"]

This call will swizzle some methods in UIApplication to capture UIEvents. If you would rather not do this, or if you already have a source of UIEvents, you can pass the following option to init to disable swizzling:

paws = MonkeyPaws(view: window!, tapUIApplication: false)

Then you can pass in events with the following call:

paws?.append(event: event) // event is UIEvent

Contributing

Feel free to file issues and send pull requests for this project! It is very new and not overly organised yet, so be bold and go ahead. We will sort out the details as we go along.

Code style is currently just four-space identation and regular Apple Swift formatting.

Also, we have adopted the Contributor Covenant as the code of conduct for this project:

http://contributor-covenant.org/version/1/4/

Thanks to

  • The Zalando Open Source Guild for helping get this project off the ground.
  • João Nunes for help with documentation.
  • Jakub Mucha for bugfixing.

TODO

SwiftMonkey

  • Write more documentation.
  • Add more input event actions.
  • Add randomised testing using public XCTest APIs instead of private ones.
    • Find clickable view and click them directly instead of clicking random locations, to compensate for the slow event generation.
  • Fix swipe actions to avoid pulling out the top and bottom panels. (This can cause the monkey to escape from your app, which can be problematic!)
  • Generally, find a quick way to see if the monkey manages to leave the application.
  • Find out how to do device rotations using XCTest private API.
  • Find out why UIAutomation actions do not work on device, but only on the simulator.
  • Investigate other methods of generating input events that do not rely on private APIs.
  • Once Swift Package Manager has iOS support, update project to support it properly.

SwiftMonkeyPaws

  • Add more customisability for the visualisation.

SwiftMonkeyExample

  • Add more UI elements, views and controls to make the example look more interesting.
  • Maybe add some actual crashes that the monkey testing can find?

Contact

This software was originally written by Dag Ågren ([email protected]) for Zalando SE. This email address serves as the main contact address for this project.

Bug reports and feature requests are more likely to be addressed if posted as issues here on GitHub.

License

The MIT License (MIT) Copyright © 2016 Zalando SE, https://tech.zalando.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

patroni

A template for PostgreSQL High Availability with Etcd, Consul, ZooKeeper, or Kubernetes
Python
6,058
star
2

postgres-operator

Postgres operator creates and manages PostgreSQL clusters running in Kubernetes
Go
3,686
star
3

skipper

An HTTP router and reverse proxy for service composition, including use cases like Kubernetes Ingress
Go
3,005
star
4

zalenium

A flexible and scalable container based Selenium Grid with video recording, live preview, basic auth & dashboard.
Java
2,380
star
5

restful-api-guidelines

A model set of guidelines for RESTful APIs and Events, created by Zalando
CSS
2,067
star
6

tailor

A streaming layout service for front-end microservices
JavaScript
1,726
star
7

logbook

An extensible Java library for HTTP request and response logging
Java
1,684
star
8

tech-radar

Visualizing our technology choices
1,491
star
9

spilo

Highly available elephant herd: HA PostgreSQL cluster using Docker
Python
1,225
star
10

intellij-swagger

A plugin to help you easily edit Swagger and OpenAPI specification files inside IntelliJ IDEA
Java
1,160
star
11

problem-spring-web

A library for handling Problems in Spring Web MVC
Java
997
star
12

nakadi

A distributed event bus that implements a RESTful API abstraction on top of Kafka-like queues
Java
928
star
13

zally

A minimalistic, simple-to-use API linter
Kotlin
873
star
14

problem

A Java library that implements application/problem+json
Java
851
star
15

zalando-howto-open-source

Open Source guidance from Zalando, Europe's largest online fashion platform
799
star
16

go-keyring

Cross-platform keyring interface for Go
Go
689
star
17

gin-oauth2

Middleware for Gin Framework users who also want to use OAuth2
Go
556
star
18

zappr

An agent that enforces guidelines for your GitHub repositories
JavaScript
543
star
19

pg_view

Get a detailed, real-time view of your PostgreSQL database and system metrics
Python
488
star
20

engineering-principles

Our guidelines for building new applications and managing legacy systems
363
star
21

gulp-check-unused-css

A build tool for checking your HTML templates for unused CSS classes
CSS
359
star
22

zmon

Real-time monitoring of critical metrics & KPIs via elegant dashboards, Grafana3 visualizations & more
Shell
355
star
23

expan

Open-source Python library for statistical analysis of randomised control trials (A/B tests)
Python
325
star
24

PGObserver

A battle-tested, flexible & comprehensive monitoring solution for your PostgreSQL databases
Python
315
star
25

riptide

Client-side response routing for Spring
Java
285
star
26

jackson-datatype-money

Extension module to properly support datatypes of javax.money
Java
240
star
27

grafter

Grafter is a library to configure and wire Scala applications
Scala
240
star
28

opentracing-toolbox

Best-of-breed OpenTracing utilities, instrumentations and extensions
Java
178
star
29

elm-street-404

A fun WebGL game built with Elm
Elm
176
star
30

tokens

Java library for conveniently verifying and storing OAuth 2.0 service access tokens
Java
169
star
31

innkeeper

Simple route management API for Skipper
Scala
166
star
32

public-presentations

List of public talks by Zalando Tech: meetup presentations, recorded conference talks, slides
165
star
33

python-nsenter

Enter kernel namespaces from Python
Python
139
star
34

dress-code

The official style guide and framework for all Zalando Brand Solutions products
CSS
129
star
35

faux-pas

A library that simplifies error handling for Functional Programming in Java
Java
128
star
36

beard

A lightweight, logicless templating engine, written in Scala and inspired by Mustache
Scala
121
star
37

friboo

Utility library for writing microservices in Clojure, with support for Swagger and OAuth
Clojure
117
star
38

spring-cloud-config-aws-kms

Spring Cloud Config add-on that provides encryption via AWS KMS
Java
99
star
39

zalando.github.io

Open Source Documentation and guidelines for Zalando developers
HTML
80
star
40

failsafe-actuator

Endpoint library for the failsafe framework
Java
53
star
41

package-build

A toolset for building system packages using Docker and fpm-cookery
Ruby
35
star
42

ghe-backup

Github Enterprise backup at ZalandoTech (Kubernetes, AWS, Docker)
Shell
30
star
43

rds-health

discover anomalies, performance issues and optimization within AWS RDS
Go
18
star
44

backstage-plugin-api-linter

API Linter is a quality assurance tool that checks the compliance of API's specifications to Zalando's API rules.
TypeScript
12
star
45

.github

Standard github health files
1
star