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.
- Launch Instruments
Open XCode ->Open Developer Tool ->Instrument
- 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.
- An instrument is launching, and Stop recording immediately. If you want to start the record, press Red button
- In the Scripts window, click Add > Create to create a new script
- 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.
- 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.
- 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
- Play your script
Press play button, the script runs, and you can stop it after logs appear.
Create iOS test program using OCUnit framework
- Start Xcode IDE, Add Unit Test Bundle target
- Write the name of the new Unit test Bundle as figure above, then click Finish
- Make Unit Test active target
- Add group for test classes
- Add Unit test class
- 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.