Session 409
๐ What's New in Testing - WWDC 2017 - Videos - Apple Developer
closure, delegate method, delayed completion ์ ํตํด ์ฝ๋ฐฑ๋ฐ์ ์ฆ์ ์คํ ๋์ง ์๋ ๊ฒ์ ํ ์คํธ Opening documents Work on background threads Communication with services and extensions Network activity Animations UI test conditions
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
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...
}
Public initializer (Decoupled from XCTestCase)
Multiple fulfillments
Inverted behavior
Launch, Terminate
Queries โ User Interface elements๋ฅผ ์ฐพ์์ค
Target Application ์ด ํ ์คํธ ํ ๋ฉ์ธ ํ๊ฒ (Project Setting์์ ์ค์ )
default initializer let taregetApp = XCUIAPplication()
appgroup ํ๋ ์ด์์ ์ฑ์ ํ ์คํธ ํ ์ ์๊ฒ ํด์ค. ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์ผ๋ฉฐ ์ํธ์์ฉํ๋ค.
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 }
ํ ์คํธ ์ค์ธ ์ฑ์ ๋ณํ๋ฅผ ๊ฐ์งํ ์ ์๋ค.
XCUIElement.screenshot
XCUIScreen.screenshot