Friday, December 14, 2018

XCUITesting : User Interface Testing iOS



UI testing gives you the ability to find and interact with the UI of your app in order to validate the properties and state of the UI elements.
UI testing also has UI recording which gives developer to generate code that exercise apps UI the same way a developer would do.

UI tests rest upon two core technologies. XCTest framework and Accessibility.

XCTest is the framework that provides UI testing capabilities. Developer need to create a UI test target, and also create UI test classes and UI test methods as a part of the project. You use XCTest assertions to validate that expected outcomes are true. Developer also get continuous integration via Xcode Server and xcodebuild. XCTest is fully compatible with both Objective-C and Swift.

Accessibility technology is used as it has rich semantic data about the UI that users can use

When we create a UI Test target, Xcode creates a default UI test group and implementation file for us with an example test template. When we create a UI test target, we specify the app that the test will address.

iOS devices need to be enabled for development and connected to a trusted host. macOS needs permission granted to a special Xcode Helper app (prompt automatically on first use)

When ui testing happens, the test code runs as a separate process, synthesising events that UI in our app responds to.

Below are the three APIs the XCUITesting is dependent on.

XCUIApplication
XCUIElement
XCUIElementQuery

Below given the sequence for UIRecroding

    Using the test navigator, create an UI testing target.

    In the template file that is created, place the cursor into the test function.

    Start UI recording.

    The app launches and runs. Exercise the app doing a sequence of UI actions. Xcode captures the actions into source in the body of the function.

    When done with the actions you want to test, stop UI recording.

    Add XCTest assertions to the source.


API tests can have both functional and performance aspects, and so can UI tests. UI tests operate at the surface space of the app and tend to integrate a lot of low level functionality into what the user sees as presentation and response.

UI tests fundamentally operate on the level of events and responses.

    Query to find an element.
    Know the expected behavior of the element as reference.
    Tap or click the element to elicit a response.
    Measure that the response matches or does not match the expected for a pass/fail result.

UI tests have both functional and performance aspects, just like unit tests.

The general pattern of a UI test for correctness is as follows:
    Use an XCUIElementQuery to find an XCUIElement.
    Synthesize an event and send it to the XCUIElement.
    Use an assertion to compare the state of the XCUIElement against an expected reference state.

To construct a UI test for performance, wrap a repeatable UI sequence of steps into the measureBlock structure


References:
https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/09-ui_testing.html

No comments:

Post a Comment