ui testing mit xcode 7

Post on 14-Jan-2017

287 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

#WISSENTEILEN

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

@_openknowledge

#WISSENTEILEN

Warum testen?

UI Testing mit Xcode 7MTC2016

Motivation

#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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Motivation

„Unit testing is not about finding bugs.“

#WISSENTEILEN

‣ Notwendig bei komplexen Systemen

‣ Sicherung von ‣ Qualität ‣ Funktionalität

‣ Wichtig bei agilen Entwicklungsprozessen ‣ Schnelle Entwicklungszyklen

UI Testing mit Xcode 7MTC2016

Motivation

#WISSENTEILEN

Wie testen?

UI Testing mit Xcode 7MTC2016

Motivation

#WISSENTEILEN

eXtreme Clicking

UI Testing mit Xcode 7MTC2016

Motivation

#WISSENTEILEN

nur auf dem Entwicklerrechner

MotivationUI Testing mit Xcode 7

MTC2016

#WISSENTEILEN

Kunden

MotivationUI Testing mit Xcode 7

MTC2016

#WISSENTEILEN

© Ultrashock - iStock

MotivationUI Testing mit Xcode 7

MTC2016

Expect the Unexpected!

#WISSENTEILEN

Anforderungen an Testabdeckung

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

MotivationUI Testing mit Xcode 7

MTC2016

#WISSENTEILEN

Was testen?

UI Testing mit Xcode 7MTC2016

Motivation

#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)

#WISSENTEILEN

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

MotivationUI Testing mit Xcode 7

MTC2016

#WISSENTEILEN

Unit Test

‣ Testen der korrekten Funktionsweise einzelner, isolierter Komponenten

‣ Automatisiert ‣ Wiederholbar

MotivationUI Testing mit Xcode 7

MTC2016

#WISSENTEILEN

UI Test

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

MotivationUI Testing mit Xcode 7

MTC2016

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie

#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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie

UI Automation

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie - UI Automation

UI Automation

‣ JavaScript ‣ Nur per Instruments ‣ Kein echtes Debugging

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie - UI Automation

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Historie

KIF – Keep It Functional

#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

#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") } }

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

+

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Integration in Xcode ‣ Test Navigator ‣ Debugging

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

+

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Per Interface Builder

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Übersicht

‣ Per Interface Builder ‣ Per API

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Vorraussetzungen

ab iOS 9

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ XCUIDevice ‣ XCUIElementQuery ‣ XCUIElement

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App

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

#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() }

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App ‣ Startparameter steuern

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App ‣ Startparameter steuern

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIApplication ‣ Einstieg in die App ‣ Startparameter steuern

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIDevice ‣ Zugriff auf „Hardware“

XCUIDevice.sharedDevice()

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIDevice ‣ Zugriff auf „Hardware“ ‣ Device Orientation

XCUIDevice.sharedDevice().orientation = .LandscapeLeft

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

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

XCUIDevice.sharedDevice().pressButton(.Home)

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

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

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

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

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ „Suche“ nach UI Elementen

app.tableViews[0].cells[0]

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ „Suche“ nach UI Elementen

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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ „Suche“ nach UI Elementen

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

#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()

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

app.tables.element.descendantsMatchingType(.StaticText)

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Descendants

app.tables.element.staticTexts

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Children

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Children

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Children

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

app.tables.element.childrenMatchingType(.Cell)

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Containment

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Containment

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

API

‣ XCUIElementQuery ‣ Containment

Application

Table

Cell

Cell„one“ Label

„two“ Label

View

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

#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)

#WISSENTEILEN

Code Diving

#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

#WISSENTEILEN

UI Testing mit Xcode 7MTC2016

Fazit

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

One more thing ...

#WISSENTEILEN

Social Media

One more thing…UI Testing mit Xcode 7

MTC2016

Broken Windows Theorie

#WISSENTEILEN

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

@_openknowledge

#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

top related