![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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/1.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/2.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/3.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/4.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/5.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/6.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/7.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/8.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/9.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/10.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/11.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/12.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/13.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/14.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/15.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/16.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/17.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/18.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/19.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/20.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/21.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/22.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/23.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/24.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/25.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/26.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/27.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/28.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/29.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/30.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/31.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/32.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/33.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/34.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/35.jpg)
⌘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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/36.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/37.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/38.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/39.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/40.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/41.jpg)
- (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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/42.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/43.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/44.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/45.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/46.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/47.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/48.jpg)
/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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/49.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/50.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/51.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/52.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/53.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/54.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/55.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/56.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/57.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/58.jpg)
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://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/59.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/60.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/61.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/62.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/63.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/64.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/65.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/66.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/67.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/68.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/69.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/70.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/71.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/72.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/73.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/74.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/75.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/76.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/77.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/78.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/79.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/80.jpg)
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](https://reader030.vdocument.in/reader030/viewer/2022040612/5f030c987e708231d4074888/html5/thumbnails/81.jpg)
http://www.organicdesign.co.nz/File:Warning.svg
Attributions
http://www.flickr.com/photos/heliotrop3/4310957752/
Thursday, January 13, 2011