73
#WISSENTEILEN UI Testing mit Xcode 7 Michael Kotten | OPEN KNOWLEDGE @michaelkotten @_openknowledge

UI Testing mit Xcode 7

Embed Size (px)

Citation preview

Page 1: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7Michael Kotten | OPEN KNOWLEDGE @michaelkotten

@_openknowledge

Page 2: UI Testing mit Xcode 7

#WISSENTEILEN

Warum testen?

UI Testing mit Xcode 7MTC2016

Motivation

Page 3: UI Testing mit Xcode 7

#WISSENTEILEN

„Wer testet, ist feige!“

„Ich weiß doch, dass mein Code funktioniert!“

„Wenn ich den Test selber schreibe, hat es eh keinen

Sinn!“„Keine Zeit für Unit Tests!“

UI Testing mit Xcode 7MTC2016

Motivation

Page 4: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Motivation

„Unit testing is not about finding bugs.“

Page 5: UI Testing mit Xcode 7

#WISSENTEILEN

‣ Notwendig bei komplexen Systemen

‣ Sicherung von ‣ Qualität ‣ Funktionalität

‣ Wichtig bei agilen Entwicklungsprozessen ‣ Schnelle Entwicklungszyklen

UI Testing mit Xcode 7MTC2016

Motivation

Page 6: UI Testing mit Xcode 7

#WISSENTEILEN

Wie testen?

UI Testing mit Xcode 7MTC2016

Motivation

Page 7: UI Testing mit Xcode 7

#WISSENTEILEN

eXtreme Clicking

UI Testing mit Xcode 7MTC2016

Motivation

Page 8: UI Testing mit Xcode 7

#WISSENTEILEN

nur auf dem Entwicklerrechner

MotivationUI Testing mit Xcode 7

MTC2016

Page 9: UI Testing mit Xcode 7

#WISSENTEILEN

Kunden

MotivationUI Testing mit Xcode 7

MTC2016

Page 10: UI Testing mit Xcode 7

#WISSENTEILEN

© Ultrashock - iStock

MotivationUI Testing mit Xcode 7

MTC2016

Expect the Unexpected!

Page 11: UI Testing mit Xcode 7

#WISSENTEILEN

Anforderungen an Testabdeckung

‣ Alles “Offensichtliche” plus …‣ … Umwelteinflüsse & Störungen ‣ … System Notifications ‣ … zu unterstützende Devices, Locales …

MotivationUI Testing mit Xcode 7

MTC2016

Page 12: UI Testing mit Xcode 7

#WISSENTEILEN

Was testen?

UI Testing mit Xcode 7MTC2016

Motivation

Page 13: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Motivation

„It makes no sense to test something that

can’t be broken (or fixed)!“(Zitat: alter weiser Mann)

Page 14: UI Testing mit Xcode 7

#WISSENTEILEN

Gute Tests ... ‣… treffen Annahmen nur einmal ‣… sind isoliert ‣… laufen unabhängig ‣… sind vorhersehbar

MotivationUI Testing mit Xcode 7

MTC2016

Page 15: UI Testing mit Xcode 7

#WISSENTEILEN

Unit Test

‣ Testen der korrekten Funktionsweise einzelner, isolierter Komponenten

‣ Automatisiert ‣ Wiederholbar

MotivationUI Testing mit Xcode 7

MTC2016

Page 16: UI Testing mit Xcode 7

#WISSENTEILEN

UI Test

‣ Wie Unit Test ‣ Fokus auf ‣ Event Handling (Tap, Swipe etc.) ‣ GUI Elemente

MotivationUI Testing mit Xcode 7

MTC2016

Page 17: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie

Page 18: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie

Das war UI Testing vor Xcode 7

‣ UI Automation ‣ KIF - Keep it functional ‣ Frank ‣ Subliminal*

* wird nicht mehr weiterentwickelt

Page 19: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie

UI Automation

Page 20: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie - UI Automation

UI Automation

‣ JavaScript ‣ Nur per Instruments ‣ Kein echtes Debugging

Page 21: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie - UI Automation

Page 22: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie

KIF – Keep It Functional

Page 23: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie - KIF

KIF – Keep It Functional

‣ Objective-C ‣ Integration in Xcode ‣ Test Navigator ‣ Debugging

‣ Gray-Box-Test ‣ nutzt private API

Page 24: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie - KIF

class CalculatorUiTests : KIFTestCase {

func testAdd() { tester.tapViewWithAccessibilityLabel("one") tester.tapViewWithAccessibilityLabel("add") tester.tapViewWithAccessibilityLabel("two") tester.tapViewWithAccessibilityLabel("equal") XCTAssertEqual(display.text!, "3", "result should be 3") } }

Page 25: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

+

Page 26: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

Page 27: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode

Page 28: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator

Page 29: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator ‣ Debugging

Page 30: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator ‣ Debugging ‣ Test recording

Page 31: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator ‣ Debugging ‣ Test recording ‣ Test Report

Page 32: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator ‣ Debugging ‣ Test recording ‣ Test Report ‣ Code Coverage

Page 33: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator ‣ Debugging ‣ Test recording ‣ Test Report ‣ Code Coverage ‣ Continuous Integration

Page 34: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator ‣ Debugging ‣ Test recording ‣ Test Report ‣ Code Coverage ‣ Continuous Integration ‣ On device

Page 35: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

+

Page 36: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

Page 37: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Per Interface Builder

Page 38: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Per Interface Builder ‣ Per API

func setValue(value: String) { self.label.text = value self.label.accessibilityValue = value }

Page 39: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Vorraussetzungen

ab iOS 9

Page 40: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ XCUIDevice ‣ XCUIElementQuery ‣ XCUIElement

Page 41: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App

override func setUp() { super.setUp() let app = XCUIApplication() app.launch() }

Page 42: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App ‣ Startparameter steuern

override func setUp() { super.setUp() let app = XCUIApplication() app.launchArguments = [ "TEST_MODE" ] app.launchEnvironment = [ "animations" : "0" ] app.launch() }

Page 43: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App ‣ Startparameter steuern

let testMode = NSProcessInfo.processInfo().arguments.contains("TEST_MODE")

Page 44: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App ‣ Startparameter steuern

if NSProcessInfo.processInfo().environment["animations"] == "0" { UIView.setAnimationsEnabled(false) }

Page 45: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App ‣ Startparameter steuern

let testMode = NSProcessInfo.processInfo().arguments.contains("TEST_MODE")

Page 46: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIDevice ‣ Zugriff auf „Hardware“

XCUIDevice.sharedDevice()

Page 47: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIDevice ‣ Zugriff auf „Hardware“ ‣ Device Orientation

XCUIDevice.sharedDevice().orientation = .LandscapeLeft

Page 48: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIDevice ‣ Zugriff auf „Hardware“ ‣ Device Orientation ‣ Hardware Buttons

XCUIDevice.sharedDevice().pressButton(.Home)

Page 49: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElement ‣ Interaktion (z.B. tap() oder swipeUp())

XCUIApplication().buttons["five"].tap()

Page 50: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElement ‣ Interaktion (z.B. tap() oder swipeUp()) ‣ Sichtbarkeit mit exists

XCTAssert(XCUIApplication().buttons["five"].exists)

Page 51: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ „Suche“ nach UI Elementen

app.tableViews[0].cells[0]

Page 52: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ „Suche“ nach UI Elementen

app.tables.element.cells.elementAtIndex(0)

Page 53: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ „Suche“ nach UI Elementen

app.tables.element.cells["cellIdentifier"]

Page 54: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ „Suche“ nach UI Elementen ‣ Ausführung erst bei Interaktion ‣ Fehler falls nicht eindeutig

app.tables.element.cells["cellIdentifier"].tap()

Page 55: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 56: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 57: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 58: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

app.tables.element.descendantsMatchingType(.StaticText)

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 59: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

app.tables.element.staticTexts

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 60: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Children

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 61: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Children

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 62: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Children

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

app.tables.element.childrenMatchingType(.Cell)

Page 63: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Containment

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 64: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Containment

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

Page 65: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Containment

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

app.cells.containingType(.StaticText, identifier: "one")

Page 66: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ Auf Elemente warten

let element = app.alerts["Timeout"] let existsPredicate = NSPredicate(format: "exists == true") expectationForPredicate(existsPredicate, evaluatedWithObject: element, handler: nil) waitForExpectationsWithTimeout(5, handler: nil)

Page 67: UI Testing mit Xcode 7

#WISSENTEILEN

Code Diving

Page 68: UI Testing mit Xcode 7

#WISSENTEILEN

UI Automation Keep it Functional UI Testing

Sprache Javascript Objective-C/Swift Objective-C/Swift

Maintainer Apple Community Apple

Accessibility ✔ ✔ ✔

Xcode ✖ ✔ ✔

Debugging ✖ ✔ ✔

Mocking ✖ ✔ ✖

Continuous Integration ✔ ✔ ✔

Zukunftssicher ✖ ✖ ✔

UI Testing mit Xcode 7MTC2016

KIF vs. UI Automation vs. UI Testing

Page 69: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Fazit

✓ Offizielle Lösung von Apple✓ Kein JavaScript mehr ✓ Test recording ✓ Schnelligkeit - Flexibilität

Page 70: UI Testing mit Xcode 7

One more thing ...

Page 71: UI Testing mit Xcode 7

#WISSENTEILEN

Social Media

One more thing…UI Testing mit Xcode 7

MTC2016

Broken Windows Theorie

Page 72: UI Testing mit Xcode 7

#WISSENTEILEN

UI Testing mit Xcode 7Michael Kotten | OPEN KNOWLEDGE @michaelkotten

@_openknowledge

Page 73: UI Testing mit Xcode 7

#WISSENTEILEN

#1, #71, #72: © pexels.com #10: © iStock.com/ultrashock

#17: © iStock.com/alexsl #39: © apple.com

#67: © 2436digitalavenue - Fotolia

UI Testing mit Xcode 7MTC2016

Bildnachweise