iOS Test Automation: XCTest at a glance

As has become common knowledge, Apple is aggressively harnessing its in-house Xcode Test Automation tool, XCTest. Keeping this in mind, we decided to perform a PoC on one of our projects at Adrosonic. And as it turns out, we have been using it as a complete automation solution for iOS apps ever since. Apple has made sure testers have a dedicated class that contains all the accessibility and assertive methods required for any regular automation—something we quite like! And that would be because testing and development should be mutually exclusive to each other, no matter how closely their paths traverse one another. With some minor tweaks to the existing methods and some more user-defined methods, we feel it suffices pretty much all our needs with respect to automating as well as verifying and establishing thorough results for all our testing scenarios. In this blog, we will not only help you with all that XCTest has in store for us, but we will also brief you on setting up a simple and scalable framework across the tool—all so you can start automating right away. So, let’s quickly take a linear walkthrough on all that XCTest has to offer to its niche group of testers.

1. First things first: XCTest Navigator:

To open the test navigator, click on the picture2 icon above the navigator panel, and it will open the test navigator. The test navigator is made up of the test list, the test indicator, and the test filter bar:

Test list: This lists the test bundles, test classes, and the tests implemented in the current project.

Click on a test in the list in order to access its code in the source editor. Test indicators: Indicators appear next to the test names in the test navigator when tests have been run. A green diamond shape with a check mark indicates that a test has passed, and a red diamond shape with an “X” indicates that a test has failed. When the code for tests is visible in the source editor, the same indicators that have been discussed appear in the source editor gutter.

Hold the pointer over any test name or indicator to display a run button. Click on the run button in order to run the test. Test Filter Bar: This lets you restrict the content that is displayed in the test list and add new test bundles and classes.
The filter bar includes the following items: The Add button: Click on this in order to add a test target or a test class. The Scope button: Toggle between showing all the tests and showing only the enabled tests in the active scheme. The Filter field: Enter text to show only the tests with matching names. The Failed test button: Toggle between showing all the tests and showing only the failing tests.

2. Adding your App as a UI Target for Automation:

In order to start automating your app, you’ll first need to add that app as a UI target. This will connect your app configurations with XCTest so that you can run tests on the associated target. It will add the basic setUp, tearDown, and test methods for you to start writing your tests there. You’ll have to enter some basic details of the app in the following pop-up after you click on it to add a target:

3. Adding a UI Test Class:

You can add multiple test classes to your project in order to enhance your scope of testing. Swift works on the OOPS concept, so you can inherit methods from across different test classes in order to cover your testing scenarios. Typically, we would like to keep separate classes for separate pages in our target app in order to follow the Page Object Model (POM). Here’s how you can add a new UI test class to your test project:

All the test classes are subclasses of XCTestCase, as mentioned previously. The XCTestCase class has all the basic functions and assertions required by automaters in order to automate and validate test scenarios. You can also enhance this class by adding more user-defined functions, as per your requirements

4. Record and Play: The best feature hands down!

Anyone who is relatively new to XCTest will find this feature quite heartening. To add to a generic record-play functionality, Apple has the following features, among several others, embedded in the record and play functionality:

  1. It records user actions with absolute precision.
  2. It provides alternatives to the existing recorded objects
  3. It records the shortest path to objects.
  4. It smartly removes duplicate code.

You can start recording anytime during your testing, with a single click on theRecordButtonbutton in the debug area. Once you click on the record button, it will build the application and start with the first landing page in your application. You can then pause and record as per your convenience. The record button is on the debug area panel by default. Also, you can add break points by clicking on theBreakPointbutton in the debug area, which is just besides the record button.

5. Linear Scalable Framework Development across XCTest:

As XCTest is closely related to with Xcode, it provides testers with great testing capabilities. Access to a lot of properties and methods of every object in your target helps enhance your testing scope and take it to greater heights, which would otherwise not be available to you through other iOS testing tools, such as Automation through Instruments, KIF (Keep it Functional), Calabash or even Earl Grey..

6. To Conclude…

XCTest a great solution for the tons of scenarios to be tested in your iOS app. Keeping in mind that it is Apple’s in-house solution gives it more access to all the features one generally performs in an app. UI usability testing is probably the hallmark of the testing tool, as all human gestures are replicated through methods that are predefined in the tool, so no more workarounds! Also, object identification is great and you can get the properties of every object with ease. Additionally, because the tool is quite neat and not many controls are present on the dashboard, it is quite user friendly. All the same, you can add controls to the dashboard as shortcuts any time you want. We found XCTest to be a great tool to cover all our automation testing needs with respect to iOS apps. To know more about the subject, contact us at

ADROSONIC and Riversand Partner to Deliver Cloud-native MDM and PIM Solutions for the Insurance Industry ​ Know More