You are on page 1of 37

TESTING

In iOS
Sam Soffes
@samsoffes
I’m a software engineer
at Scribd in San Francisco
So, testing... *sigh*
No one likes writing tests
Testing is important
Testing is important
̶
few good
There are a lot of options
Unit Testing
GHUnit
OCUnit
- (void)testFirstObject {
NSArray *array = [[NSArray alloc]
initWithObjects:@"foo", @"bar", nil];
GHAssertEqualObjects([array firstObject],
@"foo", nil);
[array release];
}
Download at sstoolk.it
Automated Testing
var target = UIATarget.localTarget();
var application = target.frontMostApp();
var window = application.mainWindow();
var view = window.elements()[0];
var buttons = window.buttons();

// Check for a button on screen


if (buttons.length != 1) {
UIALogger.logFail("FAIL: The button is
missing.");
} else {
UIALogger.logPass("PASS: There is a
button on the screen.");
}
// Make sure it's the button we want
var button = buttons.firstWithName("Tap Me");

if (!button || button.toString() ==
"[object UIAElementNil]") {
UIALogger.logFail("FAIL: The button is
missing.");
} else {
UIALogger.logPass("Pass: The button is
there.");
}
// Tap the button
button.tap();

// Check for the alert


var alert = application.alert();
if (!alert || alert.toString() == "[object
UIAElementNil]") {
UIALogger.logFail("FAIL: The alert was not
shown after pressing the button.");
} else {
UIALogger.logPass("PASS: The alert was
shown after pressing the button.");
}
Performance Testing
Questions?
Thanks!
Get my slides at samsoff.es/talks

You might also like