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

How to control state in UI Test

Shingo Tamaki
February 20, 2019

How to control state in UI Test

I considered what how to controll state in UI Test interactively.
This is summary of my idea.

Shingo Tamaki

February 20, 2019
Tweet

More Decks by Shingo Tamaki

Other Decks in Technology

Transcript

  1. XCUITestʹ͓͚Δঢ়ଶ
    ੍ޚʹ͍ͭͯߟ͑Δ

    View full-size slide

  2. XCUITestͱ͸
    XCTestʹؚ·ΕΔUI Testingͷ௨শ
    ςετର৅ͷΞϓϦʹର͠ɺϢʔβͱಉ౳ͷૢ࡞Λߦ͏UIςε
    τͷͨΊͷػೳ

    View full-size slide

  3. ঢ়ଶʹ͍ͭͯ
    UIςετ͸ΑΓϢʔβʹ͍ۙܗͰςετର৅ΞϓϦΛϒϥοΫ
    ϘοΫεతʹૢ࡞͢ΔͨΊɺ
    ಺෦͔Βม਺΍ϝιουʹΞΫηε͠΍͍͢୯ମςετʹൺ΂
    Δͱঢ়ଶΛ࡞Γʹ͍͘ͱݴ͑·͢ɻ

    View full-size slide

  4. ঢ়ଶ੍ޚͷྫ(XCTest)
    XCUIApplicationͷlaunchArguments΍launchEnvironmentΛ
    ࢖ͬͯىಈ࣌ʹઃఆ஋Λ༩͑Δ
    let app = XCUIApplication()
    app.launchArguments.append("loggedIn")
    app.launchArguments.append(contentsOf: ["-key", "abc111222333"])
    app.launchArguments.append(contentsOf: ["-skipLogin", "YES"])
    app.launchEnvironment["TestMode"] = "UITest"

    View full-size slide

  5. ঢ়ଶ੍ޚͷྫ(Target Application)
    ςετର৅ͷΞϓϦͰProcessInfoͷarguments,environment
    ͔Β஋ΛऔΓग़ͯ͠࢖༻͠·͢ɻ
    ProcessInfo.processInfo.arguments.contains("loggedIn")
    UserDefaults.standard.string(forKey: "key")
    UserDefaults.standard.bool(forKey: "skipLogin")
    ProcessInfo.processInfo.environment["TestMode"]

    View full-size slide

  6. ىಈ࣌ʹҰׅͰ༩͑Δ͔͠ͳ͍

    View full-size slide

  7. !
    ىಈޙʹ΍Εͳ͍ͩΖ
    ͏͔ʁ

    View full-size slide

  8. ྫ͑͹͜Μͳ෩ʹ
    ౎౓ςετ͔Β஋ΛૹΓɺඞཁͳΒςετର৅͔Βड͚औΔ

    View full-size slide

  9. ग़དྷ·ͨ͠

    View full-size slide

  10. Darwin notifications

    View full-size slide

  11. Darwin notificationsͱ͸ʁ
    CϕʔεͷAPIͰɺΞϓϦؒΛ·͍ͨͰ௨஌ΛૹΔ͜ͱ͕ՄೳͰ
    ͢
    !
    MMWormholeͳͲʹ΋࢖ΘΕ͓ͯΓɺWatch΍Extensionͷ։
    ൃΛͨ͠ࣄ͕͋Δਓ͸ฉ͍ͨ͜ͱ͕͋Δ͔΋͠Ε·ͤΜɻ

    View full-size slide

  12. Darwin notificationsͷΠϝʔδ

    View full-size slide

  13. Darwin notificationsͷ੍ݶ
    ௨஌ͷΈΛૹΓ·͢ɻ
    NotificationͷΑ͏ʹuserInfoͳͲ͕͋Γ·ͤΜ
    σʔλΛ΍ΓऔΓ͢ΔͷͰ͋Ε͹Կ͔ผͷ࢓૊Έ͕ඞཁʹͳΓ
    ·͢
    !

    View full-size slide

  14. ͋͞Ͳ͏͠Α͏ʁ

    View full-size slide

  15. UIPasteboard

    View full-size slide

  16. UIPasteboard
    ΞϓϦؒͷ৘ใ࿈ܞͱͯ͠ڞ௨Ͱѻ͑ΔϦιʔεͱͯ͠ݕ౼͠
    ͨதͰ࢖͍উख͕ྑͦ͞͏ͳ΋ͷͱͯ͠UIPasteboardΛ࢖ͬͯ
    ΈΔ͜ͱʹ͠·ͨ͠ɻ

    View full-size slide

  17. Telepathy (Ծ)

    View full-size slide

  18. Sample Code(XCTest)
    let exp = XCTestExpectation(description: "normal")
    Telepathy.ask(with: "normal") { message in
    exp.fulfill()
    }
    wait(for: [exp], timeout: 5)

    View full-size slide

  19. Sample Code(Target Application)
    Telepathy.listen { (message) in
    if message == "foo" {
    // something
    }
    Telepathy.answer()
    }

    View full-size slide

  20. ࣮ݱग़དྷ·ͨ͠Ͷʁ

    View full-size slide

  21. ऴΘΓʹ
    Telepathy͸·ͩΞΠσΟΞݕূஈ֊Ͱະެ։ͷϥΠϒϥϦͰ
    ͢ɻ
    ࣮ફʹ͋ͨΓ༗ޮͳϢʔεέʔεͳͲΛ໛ࡧͯ͠Δ࠷தͳͷͰ͝
    ҙݟ͍͚ͨͩΔͱ޾͍Ͱ͢ɻ

    View full-size slide