This sample iOS App and XCUITest includes an Xcode project for an app and XCUITest written using Swift. It has a shell script for submitting the tests to App Center Test. This sample does not require any App Center specific extensions.
Primary documentation for App Center Test is available at App Center Test documentation.
Primary documentation for XCUITest in App Center Test is available at Preparing XCUITest Tests for Upload.
Clone or download this repository so you can work with it locally.
Before you can run the app or XCUITest locally on a physical device or in App Center Test (which also uses physical devices) you'll need to select an Apple Signing Identiy.
- Open this project in Xcode.
- Navigate to the
Buttons
Target with Project navigator icon>Buttons
>Hide/show project targets>Buttons
Target. - Select a Team for signing.
- Do the same for the
ButtonsUITests
target.
- Open this project in Xcode.
- Run the tests locally with Xcode>Product>Test (or CMD+U).
- Create an account and setup your local environment. See Getting started with App Center Test.
- Generate a command line for upload for an iOS App using the XCUITest framework. This app and XCUITest require iOS 9.x or greater, so specify at least one device that is iOS 9.x or greater. See Starting A Test Run.
- Using the
--app name
and--devices slug
from that generated command line, modify the fileXCUITest/Buttons/app-submit.sh
to include yourapp_name
anddevices_slug
. - Run the command (from the folder
XCUItest/Buttons/
):sh app-submit.sh
If you submit the tests to App Center Test and view the Test Report you will be able to see one test step and one screenshot for the test testNoActivities
and there are three screenshots and test steps for the test testActivities
. This is a result of how the tests are written. You can compare the source code for these two tests in ButtonsUITests.swift
.
In testActivities
the test steps are wrapped in XCTContext.runActivity
and in testNoActivities
they are not. To generate screenshots and test steps wrap your test steps or sub tests in XCTContext.runActivity
. By default, screenshots are generated automatically at the end of each Activity
. The test testActivities
also demonstrates the use of a utility function screenshot
to take a screenshot at a specific point within an Activity
instead of at the end.
For more information, see Grouping Tests into Substeps with Activities.
If you are running locally on a simulator there is an issue that prevents XCUITest from starting or results in a crash of XCUITest when tapping a button with certain iOS Simulator versions. Because of this bug, avoid iOS Simulator versions 9.0, 11.0.1, 11.1, and 11.2; see: Bug Report 39348762: XCUITest crashes in -[XCElementSnapshot(Hitpoint) hitPoint:] with EXC_BAD_ACCESS . This is a simulator only issue. It does not impact running on physical devices and does not cause any problems with App Center Test.