How to speed up UI test cases in Xcode?

前端 未结 7 1625
自闭症患者
自闭症患者 2020-12-13 14:29

Since Xcode 7 we have a nice API for UI testing. Mostly I\'m satisfied with it. The only concern is related to the speed.

In the beginning an ordina

7条回答
  •  醉梦人生
    2020-12-13 15:15

    Run them in parallel.

    If you have only 1 build machine, you can use Bluepill: https://github.com/linkedin/bluepill

    If you have multiple machines, you can use Emcee: https://github.com/avito-tech/Emcee (it also works for a single machine setup)

    We have 50 hours of UI tests, and Emcee allows us to run them in 1 hour. There are several tricks to make UI tests faster, but it is pointless if you are not running them in parallel. E.g. you can't make your 25 seconds tests run in 0.5 second.


    Tricks:

    1. Run XCUIApplication without reinstalling it:
    XCUIApplication(
        privateWithPath: nil,
        bundleID: "your.bundle.id"
    )
    

    Note: you should launch app with XCUIApplication().launch() at least once per launching XCUI test runner to install the app. This requires usage of private API.

    1. You can move something to background thread. E.g.
    let someDataFromApi = getSomeData() // start request asynchronously and immediately return
    launchApp() // this can be few seconds
    useInTest(someDataFromApi) // access to data will wait request to finish
    

    You can make the code look like there is no asynchronous things, it would be easier for QA. We want to implement this, but we didn't, so it is just an idea.

    1. Switch to EarlGrey and make tests that lasts few seconds (but they will not be black box).

    2. Open screens via deep links if you have deep links.

    3. Use a lot of private API and other hacks. E.g.: instead of going via UI to Settings app and then reset privacy settings you can call some private API.

    4. Never use long sleeps. Use polling.

    5. Speed up animations. Do not disable them!

    6. Pass some flags from UI tests to app to skip initial alerts/tutorials/popups. Can save a lot of time. Be sure to have at least 1 test that checks that those alerts work.

提交回复
热议问题