Skip to content

Latest commit

ย 

History

History
114 lines (75 loc) ยท 2.72 KB

What-s-New-in-Testing.md

File metadata and controls

114 lines (75 loc) ยท 2.72 KB

What's New in Testing

Session 409

๐Ÿ”— What's New in Testing - WWDC 2017 - Videos - Apple Developer

Async Testing

closure, delegate method, delayed completion ์„ ํ†ตํ•ด ์ฝœ๋ฐฑ๋ฐ›์•„ ์ฆ‰์‹œ ์‹คํ–‰ ๋˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ํ…Œ์ŠคํŠธ Opening documents Work on background threads Communication with services and extensions Network activity Animations UI test conditions

XCTestCase APIs

    let document = UIDocument(fileURL: documentURL)
    let documentExpectation = expectation(description: "Document opened")
    
    document.open() { success in
    	XCTAssert("Failed to open file")
    	documentExpectation.fulfill()
    }
    
    waitForExpectations(timeout: 10)

Limitations โ†’ Time out is a test failure, Waiting requires test object, Hard to factor out, No nested waiting

๐Ÿ†• XCTWaiter

Extracted logic from XCTestCases

Explicit list of expectations

Calls back to XCTWaiterDelegate

Returns XCTWaiter.Result

    // Test case waits implicitly
    waitForExpectations(timeout: 10)
    ๐Ÿ‘‡๐Ÿป
     // Test case waits explicitlyโ€จ
    wait(for: [documentExpectation], timeout: 10)
    
    // Waiter instance delegates to test
    โ€จXCTWaiter(delegate: self).wait(for: [documentExpectation], timeout: 10)
    
    // Waiter class returns resultโ€จ
    let result = XCTWaiter.wait(for: [documentExpectation], timeout: 10)
    โ€จif result == .timedOut {โ€จ
    	// handling the timeout...
    }

๐Ÿ†• XCTestExpectation

Public initializer (Decoupled from XCTestCase)

Multiple fulfillments

Inverted behavior

XCUIApplication

Launch, Terminate

Queries โ†’ User Interface elements๋ฅผ ์ฐพ์•„์คŒ

Target Application ์ด ํ…Œ์ŠคํŠธ ํ•  ๋ฉ”์ธ ํƒ€๊ฒŸ (Project Setting์—์„œ ์„ค์ •)

default initializer let taregetApp = XCUIAPplication()

Multi-app Scenarios

appgroup ํ•˜๋‚˜ ์ด์ƒ์˜ ์•ฑ์„ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์คŒ. ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ  ๋ฐ›์œผ๋ฉฐ ์ƒํ˜ธ์ž‘์šฉํ•œ๋‹ค.

๐Ÿ†• Additions to XCUIApplication

New Initializers

    init(bundleIdentifier: String)
    init(url: URL) // MacOS

Activate method

    func activate()

์ด๋ฏธ ์ž‘๋™ํ•˜๊ณ  ์žˆ๋‹ค๋ฉด ์•ฑ์„ background์—์„œ foreground๋กœ ์˜ฌ๋ ค ์ฃผ๊ณ 

์•„๋‹ˆ๋ผ๋ฉด ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ.

ํ…Œ์ŠคํŠธ๋ฅผ ์‹œ์ž‘ ํ•˜๋ฉด ๋จผ์ € launch API๋Š” ์ด์ „์— ์ž‘๋™ ํ•˜๊ณ  ์žˆ๋˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ข…๋ฃŒ์‹œํ‚ฌ ๊ฒƒ. Activate๋Š” ์ด์ „ ์ƒํƒœ๋ฅผ ๋‚ ๋ฆฌ๊ณ  ์‹ถ์ง€ ์•Š๊ณ , ๊ทธ ์ „ ํŠน์ • ์‹œ์ ์—์„œ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์ข‹๋‹ค.

State Property

    var state: XCUIApplication.State { get }

ํ…Œ์ŠคํŠธ ์ค‘์ธ ์•ฑ์˜ ๋ณ€ํ™”๋ฅผ ๊ฐ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

API capturing on demand

    XCUIElement.screenshot
    XCUIScreen.screenshot