Skip to content

Latest commit

ย 

History

History
154 lines (93 loc) ยท 3.02 KB

UI-Testing-in-Xcode.md

File metadata and controls

154 lines (93 loc) ยท 3.02 KB

UI Testing in Xcode

๐Ÿ“… 2019.11.16 (ํ† )

WWDC 2015 | Session : 406 | Category : Testing

๐Ÿ”— UI Testing in Xcode - WWDC 2015 - Videos - Apple Developer

UI testing

Find and interact with UI elements Validate UI properties and state

UI recording Test reports

Core Technologies = XCTest + Accessibility

XCTest

  • Test case subclasses
  • Test methods
  • Assertions
  • Integrate with Xcode
  • CI via Xcode Server and xcodebuild
  • Swift and Objective-C

Accessibility

์žฅ์• ๊ฐ€ ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค๋„ ์•ฑ์—์„œ ๋ชจ๋“  ์‚ฌ๋žŒ์ด ๋ฐ›๋Š” ๋˜‘๊ฐ™์€ ๊ฒฝํ—˜์„ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๊ธฐ์ˆ 

  • Rich semantic data about UI
  • UIKit and AppKit integration
  • APIs for fine tuning
  • UI test interact with the app the way a user does

Requirements

UI testing depends on new OS feature

  • iOS 9, OS X 10.11

Privacy protection

  • iOS devices
    • Enabled for development
    • Connected to a trusted host running Xcode
  • OS X must grant permission to Xcode Helper
    • Prompted on first run

UI Testing Xcode Targets

UI tests have special requirement

  • Execute in a separate process
  • Permission to use Accessibility

New Xcode target templates

  • Cocoa Touch UI Testing Bundle(iOS)
  • Cocoa UI Testing Bundle(OS X)

"Target to be Tested" setting

APIs

Three new classes

  • XCUIApplication
  • XCUIElement
  • XCUIElementQuery

UIRecording

Interact with your app

Recording generates the code

  • Create new tests
  • Expand existing tests

XCUIApplication

Proxy for tested application

  • Tests run in a separate process (์•ฑ์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด๊ณผ ๋…๋ฆฝ์ )

Launch Launch ์‹œ ํ•ญ์ƒ ์ƒˆ๋กœ์šด ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ถˆ๋Ÿฌ์˜จ๋‹ค

  • Always spawns a new process
  • Implicitly terminates any preexisting instance

Starting point for finding elements

XUIElement

Proxy for element in application XCUIApplication์ฒ˜๋Ÿผ ์•ฑ์˜ proxy ์—ญํ• ์„ ํ•˜์ง€๋งŒ element๋Š” ํ…Œ์ŠคํŠธ ์•ฑ์˜ user interface element ์—ญํ• ์ด๋‹ค.

Types

  • Button, Cell, Window, etc.

Identifiers

  • Accessibility identifier, label, title, etc.

Most elements are found by combining types and identifier

Element Uniqueness

Every XCUIElement is backed by a query

Query must resolve to exactly one match

  • No matches or multiple matches cause test failure
  • Failure raised when element resolves query

Exception

  • exists property

Event Synthesis

  • Simulate user interaction on elements
  • APIs are platform-specific
    button.click()
    button.tap()
    textField.typeText("Hello, World!")

XCUIElementQuery

API for specifying elements

Queries resolve collections of accessible elements Accessibility ์—๊ฒŒ ๋ณด์ด๋Š” element๋งŒ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค

  • Number of matches: count

  • Specify by identifier: subscripting

  • Specify by index: elementAtIndex()

Accessibility and UI Testing

Accessibility data์˜ ์งˆ์ด ์ข‹์„ ์ˆ˜๋ก ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑ ํ•˜๋Š” ๊ฒƒ์ด ์‰ฝ๊ณ  ๋” ์‹ ๋ขฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.