To guarantee the quality of your iOS application, you should follow the Test-Driven development  processes shown in below figure

Your First iOS test program using UIAutomation framework

Test-Driven Development (TDD) is a Testing model which is applied to iOS application testing. In this model, tester has to follow 4 phases below:

  • Design: Figure out what you want to test, design your test cases
  • Test: Run all tests and see if test cases fail
  • Implement: Revise your code, fix bugs which cause the test to fail
  • Test again: if Fail,if you roll back to the design. If all test cases Pass, the code meets the entire tested requirement.

Setting up test environment

In order to create iOS Test Program, you need a Mac Book.Your Mac has already installed:

  • OS X. Operating system for Mac PC
  • Xcode IDE, a development tool for iOS
  • Automated Testing framework (UIAutomation, OCUnit..)
  • iOS SDK 4 (or higher)

Create iOS test program using UIAutomation framework.

  1. Launch Instruments

Open XCode ->Open Developer Tool ->Instrument

Your First iOS test program using UIAutomation framework

  1. Add Automation Instrument

In Instruments window, select Automation Instrument

Your First iOS test program using UIAutomation framework

To create a test script, you either record a Test Scenario or you program it manually.

  1. An instrument is launching, and Stop recording immediately. If you want to start the record, press Red button

Your First iOS test program using UIAutomation framework

  1. In the Scripts window, click Add > Create to create a new script

Your First iOS test program using UIAutomation framework

  1. Choose the target

You're in the Trace window, use the Choose Target pull down to navigate to the debugging version of you App.

Your First iOS test program using UIAutomation framework

In this case, I will use Apple's sample SimpleDrillDown simple app as an application under test. It has GUI below.

Your First iOS test program using UIAutomation framework

  1. Start record your script

Record your script by hitting the record button at the top or bottom of the tool.

Your First iOS test program using UIAutomation framework

Now you can do some UI action on your application under test, and your script is recorded.

  1. See your script

To see your script, hit the Trace Log/Editor Log drop down and switch to script log view.

Your First iOS test program using UIAutomation framework

You will see your recorded script

Your First iOS test program using UIAutomation framework

 

  1. Play your script

Press play button, the script runs, and you can stop it after logs appear.

Your First iOS test program using UIAutomation framework

 

Create iOS test program using OCUnit framework

  1. Start Xcode IDE, Add Unit Test Bundle target

Your First iOS test program using UIAutomation framework

  1. Write the name of the new Unit test Bundle as figure above, then click Finish
  2. Make Unit Test active target

Your First iOS test program using UIAutomation framework

  1. Add group for test classes

Your First iOS test program using UIAutomation framework

  1. Add Unit test class

Your First iOS test program using UIAutomation framework

  1. Now start your implement

Your First iOS test program using UIAutomation framework

OCUnit uses Objective-C language to create test program. Developer must have knowledge about this language.

Source code examples

This article includes some Source Code examples. They help you to understand the tutorial more clearly and quickly.

UIAutomationSample Test script for UIAutomation demo.

 

YOU MIGHT LIKE: