ADROSONIC

iOS Test Automation: XCTest at a glance​

BLOG

November 17, 2019

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:
ios

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.

iOS2

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.

iOS4

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:

iOS5
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:

iOS6

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:

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

You can start recording anytime during your testing, with a single click on the RecordButton button 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 the BreakPoint button 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 info@adrosonic.com

Featured Insights

case study

ADROSONIC Helps Aventum Achieve Excellence in Quality

case study

Quality Excellence Programme (QEP) Helps Achieve Over 50% ROI, Saves 7000 Person-Days

Use Case

Professional Indemnity Policy: Digital Solution by INSTANDA Supercharges Speed to Market

case study

Talend Enables Cost Effective, Accurate Data Migration to Digital Administration Platform

Use Case

Leveraging RPA For Document Filing in Insurance Industry

case study

Microsoft Power Platform Transforms Office Cafeteria into Online Delivery Cafe

Use Case

RPA Turns Creation of Insurance Policies into Efficient Process

Blog

5 Ways Tech Can Grow Your Insurance Business Today

Blog

API Testing is Crucial in Delivering High-Quality Applications for Your Business ​

webinar

From RPA to AI: Navigating the Automation Spectrum for Business Growth

Blog

Skyrocket Your Business: Harnessing Cloud Technology for Unprecedented Business Growth

Interview

Coffee with ADROSONIC: The Power of 100% Client Retention Rate

Blog

Top Technology Trends in Insurance Industry

e-book

Remove Tedious Tasks to Improve Employee Engagement and Retention

Interview

Coffee with ADROSONIC – Technology Trends in the Insurance Industry

webinar

Testing in the DevOps Era

webinar

An IT leader’s Keys to RPA Success

webinar

Process Automation: The Key to Your Digital Transformation

e-book

An Introduction To Robotic Process Automation

whitepaper

E-commerce Checkout Optimization

case study

Automated Payment Processing

case study

A Scalable Partner Relationship Management Automation using Salesforce​

Press Release

Matt Pesce joins ADROSONIC as CMO to drive company’s growth globally

Press Release

ADROSONIC carves out Quality Model Office, makes in-house war horse Neeraj its Head

Press Release

ADROSONIC appoints Phillip Burgess as Head of Digital Assurance Services

Press Release

ADROSONIC expands global footsteps, makes foray into Latin America region

Press Release

ADROSONIC releases business continuity plan as India battles second wave of COVID-19

Press Release

ADROSONIC to bear expenses of COVID-19 vaccination of its employees and families

whitepaper

Transforming the Insurance Industry – How Data Helps to Thrive and Survive

Press Release

Each woman has own set of challenges, they overcome them in own unique way

Press Release

ADROSONIC organizes annual event ‘Elevate 2020’

Press Release

ADROSONIC expands business in USA, announces James Oury as Partner Operations at ADROSONIC Inc

Press Release

ADROSONIC-INSTANDA launch new partnership to rev up insurance sector’s digital transformation

whitepaper

Pardot The GenNext AI driven B2B Marketing Automation Tool

Press Release

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

Press Release

ADROSONIC announces its new subsidiary ADROSONIC Inc. in Denver, Colorado, USA

case study

A Perfect Research & Development Partner for Product Roadmap Management KM

case study

Cost Effectively Delivering a Mission Critical Application Into Live it Environment

Press Release

ADROSONIC and Systems iO enter into partnership accelerate lowcode development using the OutSystems Platform

Press Release

Yammer at ADROSONIC to drive coalescence and collaboration amid Covid-19

Press Release

ADROSONIC releases its Business Continuity Plan in the Face of the COVID-19

Press Release

ADROSONIC congratulates its Non-Executive Director

Press Release

Most Innovative IT Consulting of The year 2019

Press Release

Nasscom Market Development Program

Press Release

Saleforce World Tour 2019

Press Release

Mr. Steve Jolley To The Board

Press Release

CMMI level 3

Press Release

Gold Partner

Blog

RESTful Web Services

Blog

iOS Test Automation: XCTest at a glance

Blog

Pareto Chart Analysis – Quality Tool | Vital Few vs Trivial Many