Articles, podcasts and news about Swift development, by John Sundell.

Structuring UI tests as extensions on XCUIApplication

Published on 23 Mar 2017

Most of my UI testing logic is now categories on XCUIApplication. Makes the test cases really easy to read:

func testLoggingInAndOut() {
    XCTAssertFalse(app.userIsLoggedIn)
    
    app.launch()
    app.login()
    XCTAssertTrue(app.userIsLoggedIn)
    
    app.logout()
    XCTAssertFalse(app.userIsLoggedIn)
}

func testDisplayingCategories() {
    XCTAssertFalse(app.isDisplayingCategories)
    
    app.launch()
    app.login()
    app.goToCategories()
    XCTAssertTrue(app.isDisplayingCategories)
}

Support Swift by Sundell by checking out this sponsor:

Bitrise

Bitrise: My favorite continuous integration service. Automatically build, test and distribute your app on every Pull Request — which lets you quickly get feedback on each change that you make. Start 2021 with solid continuous integration from Bitrise, using hundreds of ready-to-use steps.