XCTest is introduced by XCode 5 for iOS 7, but until XCode 8 with iOS 10, XCTest became the default and the only choice if you want to conduct UI testing, the previous UIAutomation is deprecated at that time.
Prerequisite:
XCode and XCode command line tools should be installed.
Download the sample XCOde project from here, unzip and open the Swift project.
Get Started for XCTest:
Add a new Target of iOS UI Testing through “File”->”New”->”Target…”->”iOS UI Testing Bundle”, and input all the required info.
Use the red dot (named “Record UI Test”) on the bottom to start recording, once finished, click it again to complete.
Add assertions to the ends of each scenarios, such as the script in the “UIKitCatalogUITests.swift” of XCTestSample.zip.
For the detailed usage of assertions, you can reference to the “Test Assertions” in the XCTest Topics.
It’s hard to just check the text on some labels, so if we want to check it, we need to add value to identifier of the label, then in the testing script, using following lines:
123let label=app.staticTexts["label_identifier"]XCTAssertEqual(label.label,"label_text")XCTAssert(app.staticTexts["label_text"].exists)If you want to know more usage of the XCTest, you can reference to the Cheat Sheet.