Ui testing in ios


My notes on UI-testing in Xcode

iOS UI-testing

  1. Add UITesting to your XCode project when you setup the XCode project
  2. XCUIApplication().launch()
  3. app.otherElements.children(matching: .button).element.tap()
  4. Set your cursor inside a test method and click the red record button in the right corner of xcode,
  5. click around the app to generate programatic UI-method calls
  6. Create a check: XCTAssertEqual(app.tables.cells.count, 56, "There should be 56 words matching 'test'") etc

Gotchas:

  • Internal methods will run automatically in the test. Make them private to run them from setup.
  • Prefer using: waitForExistence(timeout:) over a regular exists check
  • Prefer using firstMatch over element

Pro’s:

  • Great way to make Unit-tests that matters.

Con’s

  • Careful to not go overboard by testing everything, as that will make the app harder to develop on later

Resources: