unit and functional testing for the ios platform€¦ · unit and functional testing for the ios...

81
Christopher M. Judd Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011

Upload: others

Post on 06-Jun-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Christopher M. Judd

Unit and Functional Testing for the iOS

Platform

Thursday, January 13, 2011

Page 2: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Christopher M. JuddPresident/Consultant of

leader

Columbus Developer User Group (CIDUG)

Thursday, January 13, 2011

Page 3: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Remarkable Ohio

Free

Developed for eTech Ohio and Ohio Historical CenterThursday, January 13, 2011

Page 4: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

University System Of Ohio

FreeDeveloped for eTech Ohio and University System Of Ohio

Thursday, January 13, 2011

Page 5: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Chmod

Free Judd Solutions

Thursday, January 13, 2011

Page 6: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

December 2008 issue

Thursday, January 13, 2011

Page 7: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

How many of you are currently or have developed applications for the

iOS Platform?

Thursday, January 13, 2011

Page 8: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

How many of you have ever unit or functionally tested your iOS

application?

Thursday, January 13, 2011

Page 9: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

How many of you have ever unit tested on another platform or language?

Thursday, January 13, 2011

Page 10: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Why aren’t you testing your iOS applications?

Thursday, January 13, 2011

Page 11: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Thursday, January 13, 2011

Page 12: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

iOS unit and functional testing is neither straight forward or easy

Thursday, January 13, 2011

Page 13: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

iOS Unit Testing Challenges

Toooo many steps to get startedNo green bar/red barCan’t run individual testsUnit test template code contains to muchUnit tests can not be debugged out of the boxLittle documentationMultiple targetsOnly includes very basic testing support

No mock framework included

Thursday, January 13, 2011

Page 14: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

iOS Functional Testing Challenges

Thursday, January 13, 2011

Page 15: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

iOS Functional Testing Challenges

Thursday, January 13, 2011

Page 16: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Testing Coverage

The Objective-C Programming Language

Thursday, January 13, 2011

Page 17: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Testing Coverage

The Objective-C Programming Language

Thursday, January 13, 2011

Page 18: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Unit Testing

Thursday, January 13, 2011

Page 19: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Unit Testing Basics

Thursday, January 13, 2011

Page 20: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Why Unit Test?

Improves designFacility change and refactoringSimplifies integrationProvides executable documentation

Thursday, January 13, 2011

Page 21: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

includes also known as

SenTestingKit

Thursday, January 13, 2011

Page 22: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Logic Test == Unit TestApplication Test == More Functional Test

Thursday, January 13, 2011

Page 23: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Getting Started

Thursday, January 13, 2011

Page 24: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-

Unit_Testing_Applications/unit_testing_applications.html#//apple_ref/doc/uid/TP40007959-CH20-SW3

Setup documentation

Thursday, January 13, 2011

Page 25: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-

Unit_Testing_Applications/unit_testing_applications.html#//apple_ref/doc/uid/TP40007959-CH20-SW3

Setup documentation

orios developer guide unit testing

Thursday, January 13, 2011

Page 26: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Unit Testing Setup Steps

1. Add unit test bundle target2. Make unit test target active3. Add group for test classes4. Add unit test class

Thursday, January 13, 2011

Page 27: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Add Unit Test Bundle Target

Thursday, January 13, 2011

Page 28: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Make Unit Test Target Active

Thursday, January 13, 2011

Page 29: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Add Group for Test Classes

Thursday, January 13, 2011

Page 30: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Add Unit Test Class

Should end in TestShould be in a separate directory

Must be have UnitTests target checked

Thursday, January 13, 2011

Page 31: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Generated Test Class#define USE_APPLICATION_UNIT_TEST 1

#import <SenTestingKit/SenTestingKit.h>#import <UIKit/UIKit.h>//#import "application_headers" as required

@interface SimpleTest : SenTestCase {}

#if USE_APPLICATION_UNIT_TEST- (void) testAppDelegate; // simple test on application#else- (void) testMath; // simple standalone test#endif

@end

#import "SimpleTest.h"

@implementation SimpleTest

#if USE_APPLICATION_UNIT_TEST // all code under test is in the iPhone Application

- (void) testAppDelegate { id yourApplicationDelegate = [[UIApplication sharedApplication] delegate]; STAssertNotNil(yourApplicationDelegate,

@"UIApplication failed to find the AppDelegate"); }

#else // all code under test must be linked into the Unit Test bundle

- (void) testMath { STAssertTrue((1+1)==2, @"Compiler isn't feeling well today :-(" ); }

#endif@end

*Test.h

*Test.m

Thursday, January 13, 2011

Page 32: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Generated Test Class#define USE_APPLICATION_UNIT_TEST 1

#import <SenTestingKit/SenTestingKit.h>#import <UIKit/UIKit.h>//#import "application_headers" as required

@interface SimpleTest : SenTestCase {}

#if USE_APPLICATION_UNIT_TEST- (void) testAppDelegate; // simple test on application#else- (void) testMath; // simple standalone test#endif

@end

#import "SimpleTest.h"

@implementation SimpleTest

#if USE_APPLICATION_UNIT_TEST // all code under test is in the iPhone Application

- (void) testAppDelegate { id yourApplicationDelegate = [[UIApplication sharedApplication] delegate]; STAssertNotNil(yourApplicationDelegate,

@"UIApplication failed to find the AppDelegate"); }

#else // all code under test must be linked into the Unit Test bundle

- (void) testMath { STAssertTrue((1+1)==2, @"Compiler isn't feeling well today :-(" ); }

#endif@end

*Test.h

*Test.m

Thursday, January 13, 2011

Page 33: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Create Custom User Templates

#import <SenTestingKit/SenTestingKit.h>

@interface SimpleTests : SenTestCase {

}

@end

@implementation SimpleTests

- (void) testMethod { STAssertTrue(true, @"message"); }

@end

*Test.m

Thursday, January 13, 2011

Page 34: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Running Unit Tests

Thursday, January 13, 2011

Page 35: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

⌘Bor

Build > Build

with unit test target selected

or

Thursday, January 13, 2011

Page 36: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

False

Nothing to worry aboutReal Failure

Thursday, January 13, 2011

Page 37: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Writing Unit Tests

Thursday, January 13, 2011

Page 38: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Basic Unit Test

#import <SenTestingKit/SenTestingKit.h>

@interface MyUnitTest : SenTestCase {

}

@end@implementation MyUnitTest

- (void) setUp { // initialize tests}

- (void) testMethod { // Test code}

- (void) tearDown { // clean up after test}

@end

*Test.m must extend SenTestCase

must return void and take no parameters

test methods must begin with test

Thursday, January 13, 2011

Page 39: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Assert Macros

STAssertNil(a1, description, ...)STAssertNotNil(a1, description, ...)STAssertTrue(expression, description, ...)STAssertFalse(expression, description, ...)STAssertEqualObjects(a1, a2, description, ...)STAssertEquals(a1, a2, description, ...)STAssertEqualsWithAccuracy(left, right, accuracy, description, ...)STAssertThrows(expression, description, ...)STAssertThrowsSpecific(expression, specificException, description, ...)STAssertThrowsSpecificNamed(expr, specificException, aName, description, ...)STAssertNoThrow(expression, description, ...)STAssertNoThrowSpecific(expression, specificException, description, ...)STAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...)STFail(description, ...)STAssertTrueNoThrow(expression, description, ...)STAssertFalseNoThrow(expression, description, ...)

Thursday, January 13, 2011

Page 40: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Basic Unit Test Example

#import <Foundation/Foundation.h>#import <SenTestingKit/SenTestingKit.h>

@interface MyUnitTest : SenTestCase { NSMutableArray* _array;}

@end

@implementation MyUnitTest

- (void) setUp { _array = [[NSMutableArray arrayWithObjects:@"1", @"2", @"3", nil] retain];}

- (void) testSize { STAssertEquals(3, (int)[_array count], @"Size must be three.");}

- (void) testIndex { STAssertEqualObjects(@"2", [_array objectAtIndex:1], @"Must retrieve object at index of 1.");}

- (void) tearDown { [_array release];}

@end

*Test.m

Thursday, January 13, 2011

Page 41: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

- (void) testSimple { Simple* simple = [[[Simple alloc] init] retain]; STAssertEquals(3, [simple coolMethod], @""); [simple release];}

Test TargetClasses under test must also target Test target or add your application target as direct dependency

Solutions

Thursday, January 13, 2011

Page 42: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Debugging Unit Tests

Thursday, January 13, 2011

Page 43: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Thursday, January 13, 2011

Page 44: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

NSLog does not even work by default

Thursday, January 13, 2011

Page 45: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

http://www.grokkingcocoa.com/how_to_debug_iphone_unit_te.html

Thursday, January 13, 2011

Page 46: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Debugging Unit Test Steps

1. Delete the Run Script2. Create otest executable3. Configure arguments4. Run tests

Thursday, January 13, 2011

Page 47: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Delete the Run Script

Delete

Thursday, January 13, 2011

Page 48: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/Developer/usr/bin/otest

Create otest Executable

Thursday, January 13, 2011

Page 49: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Configure Argumentsname of unit test bundle

I don’t even know

Thursday, January 13, 2011

Page 50: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Run Testswith unit test target and

executable selected ⌘⏎or

Build > Build and Go

test resultsThursday, January 13, 2011

Page 51: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Run Testswith unit test target and

executable selected ⌘⏎or

Build > Build and Go

test resultsNo more Red barThursday, January 13, 2011

Page 52: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Additional Unit Testing

Thoughts

Thursday, January 13, 2011

Page 53: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

http://www.mulle-kybernetik.com/software/OCMock/

hamcrest http://code.google.com/p/hamcrest/

http://code.google.com/p/uispec/

#import <SenTestingKit/SenTestingKit.h>

#define HC_SHORTHAND#import <OCHamcrestIOS/OCHamcrestIOS.h>

@interface Hamcrest : SenTestCase {}@end

@implementation Hamcrest

- (void) testMethod { assertThat(@"cool", equalTo(@"cool"));}

@end

-(void)itShouldHaveDefaultUsers {        //Check that all default users are in list        [[app.tableView.label text:@"Larry Stooge"] should].exist;        [[app.tableView.label text:@"Curly Stooge"] should].exist;        [[app.tableView.label text:@"Moe Stooge"] should].exist;}

- (void)testReturnsStubbedReturnValue{ id returnValue;

[[[mock stub] andReturn:@"megamock"] lowercaseString]; returnValue = [mock lowercaseString];

STAssertEqualObjects(@"megamock", returnValue, @"Should have returned stubbed value."); }

Thursday, January 13, 2011

Page 54: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Functional Testing

Thursday, January 13, 2011

Page 55: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

UI Automation

Thursday, January 13, 2011

Page 56: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Included in

Thursday, January 13, 2011

Page 57: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Thursday, January 13, 2011

Page 58: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Device Simulator

Thursday, January 13, 2011

Page 59: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

https://github.com/cjudd/PlainNote

derived from

https://github.com/vkoser/PlainNote

Example Application

Thursday, January 13, 2011

Page 60: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Running UI Automation

Scripts

Thursday, January 13, 2011

Page 61: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

1. Start Instruments2. Select Automation Instrument

3. Select Target App4. Select Script5. Record (Play)

Thursday, January 13, 2011

Page 62: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Test Results

Thursday, January 13, 2011

Page 63: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Writing UI Automation

Scripts

Thursday, January 13, 2011

Page 64: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

UIATargetUIAApplication

UIAWindowUIANavigationBar

UIATableViewUIATableCell

Element Tree

UIATarget.localTarget().frontMostApp() .mainWindow().tableViews()[0].cells()[0]

Thursday, January 13, 2011

Page 65: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

UIATarget.localTarget() .logElementTree();

Technique to visualize element tree

Thursday, January 13, 2011

Page 66: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

var target = UIATarget.localTarget();var app = target.frontMostApp();var window = app.mainWindow();

function testDisplayingHelp(testName) {! UIALogger.logStart(testName);! try {! ! htmlIsDisplayed = false;! !! ! app.toolbar().buttons()["Help"].tap();

! ! // without the delay the element was not on the screen! ! target.delay(1);! !! ! // No good way to get to the URL or contents of a WebView! ! webView = window.scrollViews()[0].webViews()[0];! ! if("Create" == webView.links()[0].name()) {! ! ! htmlIsDisplayed = true;! ! }! !! ! window.navigationBar().leftButton().tap();! !! ! if(htmlIsDisplayed) {! ! ! UIALogger.logPass(testName);! ! } else {! ! ! UIALogger.logFail(testName);! ! }! !! } catch (e) {! ! UIALogger.logError(e);! ! UIATarget.localTarget().logElementTree();! ! UIALogger.logFail(testName);! }}

testDisplayingHelp("Open Help Test");

Start test

End test

Example

Test

SCRIT

Thursday, January 13, 2011

Page 67: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Instead ofwindow.scrollViews()[0].textViews()[0].setValue("CodeMash is cool!!!");

window.scrollViews()[0].textViews()["note"].setValue("CodeMash is cool!!!");

use

Thursday, January 13, 2011

Page 68: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

UITarget.localTarget().captureScreenWithName("help_screen");

Does not work in simulator :(

Thursday, January 13, 2011

Page 69: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

When things don’t work

Thursday, January 13, 2011

Page 70: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

When things don’t work

UIATarget.delay(1);

add

Thursday, January 13, 2011

Page 71: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Make it easier with tuneup provides templates and asserts

https://github.com/alexvollmer/tuneup_js

#import "tuneup/tuneup.js"

test("Open Help Test", function(target, app) {! ! app.toolbar().buttons()["Help"].tap();! ! // without the delay the element was not on the screen target.delay(1);! target.captureScreenWithName("help_screen");! ! // No good way to get to the URL or contents of a WebView! webView = app.mainWindow().scrollViews()[0].webViews()[0]; ! assertEquals("Create", webView.links()[0].name(), "HTML must be displayed");! ! app.mainWindow().navigationBar().leftButton().tap();

});

Thursday, January 13, 2011

Page 72: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

http://www.cheezyworld.com/2010/11/09/ui-tests-not-brittle/

Page Object

Thursday, January 13, 2011

Page 73: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

works with other instrumentscan run in the simulator or the device

no command-line automationno fixtures (setup, teardown)difficult to debug (element tree & delays)little documentationtest run must be manually stopped

Thursday, January 13, 2011

Page 74: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

UI Automation Resources

UI Automation Reference Collectionhttp://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html

Session 306 - Automation User Interface Testing with Instruments

Thursday, January 13, 2011

Page 75: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

iCuke

https://github.com/unboxed/icukeThursday, January 13, 2011

Page 76: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Feature: Adding a note In order to remember an important item As a common person I want to add a note to my collection of notes

Background: Given "PlainNote.xcodeproj" is loaded in the iphone simulator

Scenario: Adding a note When I tap "Add" And I type "CodeMash is Cool!!!" And I tap "Save" Then I should see "CodeMash is Cool!!!"

Cuke Script

Thursday, January 13, 2011

Page 77: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

can be automatedhuman readableeasy to write

can only run on simulatorlittle documentationcan not run in instruments

Thursday, January 13, 2011

Page 78: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

http://pragprog.com/magazines/2010-07/bdd-on-iphone-icuke

Resources

Thursday, January 13, 2011

Page 79: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

Great iOS Resources

The Objective-C Programming Language

Thursday, January 13, 2011

Page 80: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

President/Consultant/Authoremail: [email protected]: www.juddsolutions.comblog: juddsolutions.blogspot.comtwitter: javajudd

Christopher M. Judd

Thursday, January 13, 2011

Page 81: Unit and Functional Testing for the iOS Platform€¦ · Unit and Functional Testing for the iOS Platform Thursday, January 13, 2011. Christopher M. Judd ... Remarkable Ohio Free

http://www.organicdesign.co.nz/File:Warning.svg

Attributions

http://www.flickr.com/photos/heliotrop3/4310957752/

Thursday, January 13, 2011