17
Automated Xcode 7 UI Testing HelsinkiOS 26 August 2015

Automated Xcode 7 UI Testing

Embed Size (px)

Citation preview

Page 1: Automated Xcode 7 UI Testing

Automated Xcode 7

UI TestingHelsinkiOS 26 August 2015

Page 2: Automated Xcode 7 UI Testing

Xcode 7 Features

— Testability. Write tests of Swift 2.0 frameworks and apps with access to all your public and internal routines

— User interface testing and recording. Test applications at the user interface surface with elements, queries, and simulated events. The UI recording feature enables capture of UI actions into source to facilitate creating tests (DEMO)

— App thinning (iOS 9 SDK), Xcode bots + OS X Server with on demand resources (ou-es ten server)

Page 3: Automated Xcode 7 UI Testing

Xcode 7 Features (cont)

— Free Provisioning. Develop on your own device, mechanism to provision and install development project on physical devices for testing and evaluation.

— Code coverage. Provides report information to evaluate a test suite for completeness.

Page 4: Automated Xcode 7 UI Testing

Code Coverage

— Visualize the completeness of your test suite by enabling code coverage for your scheme. The code coverage tab in the test report shows which files, functions and lines of code were exercised and, more importantly, which were not exercised. The source code editor can also show code coverage information inline, allowing you to see at a glance which lines—and parts of a line—the tests exercised. (3555436)

Page 5: Automated Xcode 7 UI Testing
Page 6: Automated Xcode 7 UI Testing

Beta 4

— Using UI recording generates code for iOS gestures like doubleTap, twoFingerTap, longPress, swipeUp, swipeDown, swipeLeft, and swipeRight. (20278248)

— Code coverage works with UI testing. (20966994)

Page 7: Automated Xcode 7 UI Testing

Beta 5

— Code Coverage now supports files in static libraries. The source files show up under each binary that links the static library in the Coverage tab of the Test Report. The source editor shows coverage numbers aggregated across all binaries. (21984681)

Page 8: Automated Xcode 7 UI Testing

Beta 6

— XCTest offers API to automate complex controls such as date pickers. (20577276)

— Apps with names that contain parenthesis can be exported from the Archives organizer. (22142125)

— Ability to interact with hardware buttons, like XCUIDeviceButtonHome.

— Ability to interact with XCUIElementTypeSlider and XCUIElementTypePickerWheel

— Ability to handle alerts that gets in the way with the new add/removeUIInterruptionMonitor APIs

Page 9: Automated Xcode 7 UI Testing

Known Problems (Beta 6)

— UI testing cannot identify elements using information from their accessibility title element. Workaround: Set an accessibility identifier instead. (20409319)

— UI testing cannot record or interact with popovers on OS X. (21162677)

— UI tests do not support key modifiers on iOS. (20185910, 21033224)

— When recording a UI Test for an OS X app, Xcode Helper, not Xcode, asks to use the Accessibility APIs. This app uses the Accessibility APIs when running UI Tests. (21211897)

Page 10: Automated Xcode 7 UI Testing

Syntax - XCUIApplication

— Proxy to application, separate from app (runs in separate process)

— Can control when to launch or terminate app

app.launchEnvironment = ["myValue": "value"]app.launch()

if let value = NSProcessInfo.processInfo().environment["myValue"]{ // do something with value}

Page 11: Automated Xcode 7 UI Testing

Syntax - XCUIElement

— Application is a tree of elements with hierarchy (think DOM tree)

— Element must be unique

— Based on UIControl (button, table cell, window)

— Accessibility identifier, label, title, etc.

— Custom element visibility e.g. via Interface Builder Accessibility Inspector

Page 12: Automated Xcode 7 UI Testing

Syntax - XCUIElementQuery

— Must resolve to single element, otherwise failure

— Evaluated on-demand and re-evaluated when used (think URL lifecycle)

— "exists" property can be used to safely test elements

— Elements visible via accessibility

— Relationships and filtering

— Chain queries

Page 13: Automated Xcode 7 UI Testing

Syntax - XCTest Assertions 1

XCTAssert(expression, format...)XCTAssertTrue(expression, format...)XCTAssertFalse(expression, format...)XCTAssertEqual(expression1, expression2, format...)XCTAssertNotEqual(expression1, expression2, format...)XCTAssertEqualWithAccuracy(expression1, expression2, accuracy, format...)XCTAssertNotEqualWithAccuracy(expression1, expression2, accuracy, format...)XCTAssertNil(expression, format...)XCTAssertNotNil(expression, format...)XCTAssertNil(expression, format...)XCTAssertNotNil(expression, format...)

1 XCTestCase / XCTestExpectation / measureBlock() at NSHipster

Page 14: Automated Xcode 7 UI Testing

Debug

— Use breakpoints in test cases

— Same familiar LLDB debugger and commands 2

— Test reports at Xcode Report Navigator

— Automatic screenshots

— Just re-record test cases, it's that easy !!!

2 About LLDB and Xcode by Apple

Page 15: Automated Xcode 7 UI Testing

Demo...awesome !!! Just look at that dynamic realtime code refactoring, when recording test cases O_O

Page 16: Automated Xcode 7 UI Testing

More info

— Xcode 7 Beta 6 Release Notes

— WWDC 2015 video + PDF 406: UI Testing in Xcode

— WWDC 2015 video + PDF 410: Continuous Integration and Code Coverage in Xcode

— WWDC 2014 video + PDF 415: Continuous Integration with Xcode 6

— XCTest and UI Testing documentation by Joe Maselotti

— XCTestCase / XCTestExpectation / measureBlock() at NSHipster

— UIAccessibility documentation by Apple

Page 17: Automated Xcode 7 UI Testing

Thank You!Any questions? SlideShare.Jouni Miettunen - [email protected]@jomtwi

at Elisa Software Services, looking for mobile developers