Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UI testing in XCode7

UI testing in XCode7

horimislime

June 30, 2015
Tweet

More Decks by horimislime

Other Decks in Technology

Transcript

  1. ✔ UI Testing in XCode7
    Google I/O & WWDCใࠂձ@Fablic
    @horimislime

    View full-size slide

  2. ࣗݾ঺հ & ࿩͢͜ͱ
    • ɹ @horimislime
    • ɹ גࣜձࣾτϨλ
    • XCode7Ͱ௥Ճ͞ΕͨUI Testingͷ࿩Ͱ͢

    View full-size slide

  3. ΍ͬͯΔ͜ͱ
    • BtoBࣄۀɻக໋తόά ≒ ܖ໿ղফ
    • ςετ΍Ζ͏ → KIFಋೖ΁ (WWDCલ)
    • UI Testingొ৔

    View full-size slide

  4. UI TestingͰԿ͕มΘΔ͔ʁ
    • جຊతʹ͸KIFͱࣅ͍ͯΔ
    • γϯϓϧͳAPIɻᙱ͍ͱ͜Ζʹख͕ಧ͖ͦ͏
    • UI RecordingɾScreenShotͷࣗಈࡱӨ

    View full-size slide

  5. func testReserve() {
    // tester.tapViewWithAccessibilityLabel("৽ن༧໿")
    XCUIApplication().buttons["৽ن༧໿"].tap()
    }

    View full-size slide

  6. ίʔυ͸”جຊ”खॻ͖ෆཁ
    • UI RecordingͰSimulatorૢ࡞ɾίʔυੜ੒
    • ViewͷAccessibilityLabelࢦఆ͕”΄΅”ෆཁ

    View full-size slide

  7. ίʔυ͸”جຊ”खॻ͖ෆཁ
    • UI RecordingͰSimulatorૢ࡞ɾίʔυੜ੒
    • ViewͷAccessibilityLabelࢦఆ͕”΄΅”ෆཁ

    View full-size slide

  8. ͋͘·Ͱɺجຊతʹ͸
    • AccessibilityLabelͷઃఆ͸ਪ঑͞ΕͯΔ
    • Label͕ແ͍ͱݫ͍͠έʔε΋
    XCUIApplication().childrenMatchingType(.Window).elementAtIndex(0)
    .childrenMatchingType(.Unknown).elementAtIndex(0)
    .childrenMatchingType(.Unknown).elementAtIndex(0)
    .childrenMatchingType(.Unknown).elementAtIndex(0)
    .childrenMatchingType(.Unknown).elementAtIndex(0)
    .childrenMatchingType(.Unknown).elementAtIndex(1)
    .childrenMatchingType(.Unknown).elementAtIndex(0)
    .childrenMatchingType(.Button).elementAtIndex(0).tap()

    View full-size slide

  9. ScreenShotͷࣗಈࡱӨ
    • tap()ͳͲUIૢ࡞લʹը໘ΛࡱӨͯ͘͠ΕΔ

    View full-size slide

  10. xcodebuildͰ΋
    $ xcodebuild 

    -workspace Toreta.xcworkspace 

    -scheme "Toreta UI Tests" 

    -destination 'platform=iOS Simulator,name=iPad Air 2,OS=9.0' 

    -derivedDataPath './output' test

    View full-size slide

  11. ίʔυ্ͰࡱӨ͸΋͏ཁΒͳ͍ʁ
    • Snapshot TestingΈ͍ͨͳࣄ͚ͨ͠Ε͹ݫ͍͠
    • ը૾ϑΝΠϧ໊ͷࢦఆ͕Ͱ͖ͳ͍…
    • ςετຖʹը໘ͷࡱӨ͍͚ͨͩ͠ͳΒ

    View full-size slide

  12. ݸਓతʹخ͍͠ͱ͜Ζ
    • Simulatorͷىಈɾఀࢭ͕ίʔυ্ͰՄೳʹ
    • ࠔͬͯͨ͜ͱ

    - TOPը໘ˠઃఆը໘΁ͷભҠΛςετ

    - TOPը໘ˠ͓஌Βͤը໘΁ͷભҠΛςετ
    • ςετ։࢝࣌͸ΞϓϦىಈ௚ޙͷঢ়ଶʹ

    View full-size slide

  13. override func setUp() {

    XCUIApplication().launch()
    }
    override func tearDown() {

    XCUIApplication().terminate()
    }

    View full-size slide

  14. Simulator੍ޚ͕ॊೈʹ
    • ςετ։࢝࣌͸ΞϓϦ্ཱͪ͛ͨ௚ޙͷঢ়ଶ
    • tearDown()ͰTOP΁໭Δॲཧ͕ෆཁʹ
    • Simulatorͷىಈ৚݅΋ࢦఆՄೳ

    View full-size slide

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

    View full-size slide

  16. override func setUp() {
    super.setUp()
    let app = XCUIApplication()
    app.launchArguments += ["-AppleLanguages (English)"]
    app.launch()
    }

    View full-size slide

  17. ͜ΕΒΛ౿·͑ͯ
    • ৽نͰॻ͘UI Testʹ͸࢖ͬͯ΋͍͍͔΋
    • ෳ਺ݴޠͰͷςετ͸AccessibilityLabelඞਢ

    - XCUIApplication().buttons[“ઃఆ”].tap() // Fail!!
    • KIFͰॻ͍ͨςετίʔυɺϓϥΠεϨε

    View full-size slide

  18. ·ͱΊ
    • XCode7͔ΒUIͷࣗಈςετ͕ڧԽ
    • FluentͳAPIɺSimulator΋ॊೈʹૢ࡞Մ
    • UI RecordingͰಋೖ΋ΧδϡΞϧʹ

    View full-size slide