Friday, January 22, 2016

Your First iOS test program using UIAutomation framework

To guarantee the quality of your iOS application, you should follow the Test-Driven development  processes shown in below figure
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
  1. Add Automation Instrument
In Instruments window, select Automation Instrument
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
  1. In the Scripts window, click Add > Create to create a new script
  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.
In this case, I will use Apple's sample SimpleDrillDown simple app as an application under test. It has GUI below.
  1. Start record your script
Record your script by hitting the record button at the top or bottom of the tool.
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.
You will see your recorded script

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

Create iOS test program using OCUnit framework
  1. Start Xcode IDE, Add Unit Test Bundle target
  1. Write the name of the new Unit test Bundle as figure above, then click Finish
  2. Make Unit Test active target
  1. Add group for test classes
  1. Add Unit test class
  1. Now start your implement
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.

No comments:

Post a Comment

Evil Twin attack

Evil Twin Attack is attack is frequently carried upon wireless access points with malicious intentions. This attack happens when...