“Quality is never an accident; it is always the result of intelligent effort.” – John Ruskin
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.
As a developer, ensuring a bug-free and high-quality app or product can be a daunting task. Properly studying and analyzing test cases is crucial to avoid any potential issues down the line. Don’t risk encountering problems later on – invest in thorough testing now for peace of mind in the future.
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.
Never miss an update from us. Join 10,000+ marketers and leaders.
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
- Unit Test (Test of specific case in the class)
- 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:
1 | 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.
1 2 3 | 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.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 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
Are you tired of manually testing your app’s user interface for every possible scenario? Look no further than automated UI testing! With Andolasoft’s expertise in iOS UI testing, you can save time and make coding even more enjoyable. Trust us to cover all your user scenarios and functionalities. Book a free consultation today to see how we can improve your app’s quality.