Stay on Top with latest happenings: Subscribe Now

Automated UI Testing in iOS – is it the Future of App Testing!

Automated UI Testing in iOS – is it the Future of App Testing!

Automated UI Testing

“Quality is never an accident; it is always the result of intelligent effort.” – John Ruskin

Sir John Ruskin did taught us a very important lesson in the line of testing. Though, we think testing is a manual process of careful study and intelligent analysis. Time is moving faster than we can think and so is the testing procedures.

Automated UI testing is the new key for iOS app examinations. Moreover, this is going to change the entire methodology of iOS App Development Process.

You probably heard about automated testing before. Nowadays, people are talking a lot about automated testing especially when it comes to app and product quality.

It’s always a big challenge for developers to make the app or a product bug free and improve its overall quality. Studying and analyzing the test cases for the projects are highly important and you might get into big trouble(which we do not want at all) if you will not write the tests of your projects. If not immediately (or at that moment), you may get affected in future in the long run.

Today in this article, I am going to enlighten you the different ways you can test your iOS app or a product as well as guide you in writing Automation UI Tests for your apps.

Normally, testing is divided into two categories – Manual Testing and Automation Testing.

Manual testing is the process to test your app or product manually and I’m sure everyone has a good knowledge about manual testing and I don’t want to waste your time telling you details on this.

So, let us get started with Automated Testing in IOS;

Generally, Automated Tests are two types in iOS

  1. Unit Test (Test of specific case in the class)
  2. UI Test or Integration Test (individual modules or testing of groups)

Before telling the process how to write automated UI tests for our app, you might be thinking that why you should automated UI tests for your product or app?

Let’s have look at the key benefits automated UI tests below.

  • To minimize time spent on manual testing.
  • To avoid regression bugs. If you are changing something in the code then you must test it again to check whether it doesn’t break anything and the app is still works as expected.
  • It helps to document our code.
  • It provides visual run – through our app.

What is UI Testing?

UI test is composed of actions that a user can take. It’s like a step-by-step guide with some expectations along the way.

Let’s have a look at the common format with example

Do something

Expect something to happen

Example:

Pull to refresh

We can see new things on the top

How to write UI Test?

First of all we need a framework called KIF- Keep It Functional (An iOS integration test framework which allows for easy automation of iOS apps and performs the tests using a standard XCTest testing target), which offers a whole lot of APIs to deal with UI interactions.

For Example:

Example to fill some text in the text field:

tester().enterTheText("some text", intoViewWithAccessibilityLabel: "textfield name")

Here,accessibility label is a name you give for each UIView to distinguish among them.

How to setup KIF for UI Testing?

Step 1:

Import KIF and Nimble

Nimble is a framework to help you to express your expectation in test.

pod 'KIF'

pod 'Nimble'

Step 2:

Create KIF Helper

Step 3:

Create Bridging Header

Step 4:

Create our UI Test

Create new file in the test target.

Then import KIF

Note: 1) your test must be a subclass of KIFTestCase
2) Test methods must begin with the word test

For example test the login screen with empty username and password.

Scenario: Empty username and password

Given I clear out the username and password fields

When I click"Login" button

Then I expect to see alert "Username cannot be empty"

functestForBlankUsernameAndPassword() {

clearOutUsernameAndPasswordFields()

ClickButton("Login")

expectedAlert("Username cannot beleft blank")

clickButton("OK")

}

funcclearOutUsernameAndPasswordFields() {

tester().clearTextFromViewWithAccessibilityLabel("Login - Username")

tester().clearTextFromViewWithAccessibilityLabel("Login - Password")

}

funcclickedButton(buttonName: String) {

tester().tapViewWithAccessibilityLabel(buttonName)

}

funcexpectedAlert(text: String) {

tester().waitForViewWithAccessibilityLabel(text)

}

Now we can run our test by pressing cmd + U. The simulator will pop up and run over your steps automatically.

Finale – in the end

UI test is easy to learn but it gives many benefits to us. By this, you can cover all your scenarios and functionalities as a user. It will help you to save time and make the coding funnier.

Omkar
Omkar Rath

Social Media Analyst, Research Writer, Sales & Business Development Expert, Blog Writer, Corporate Trainer, Communication Trainer, Startup, Tech News, Digital Marketing. Positive, seasoned, mature, experienced with international sales management and account management with Product Branding, Marketing and Customer Success Management Experience. Most important of all – A Husband.

Shares