Slide 1

Slide 1 text

Automated Testing with iOS Felix Schulze Teamlead Mobile Software Development

Slide 2

Slide 2 text

@x2on Every change can break your app! Picture: http://fav.me/d3g96mr

Slide 3

Slide 3 text

@x2on Break = Review

Slide 4

Slide 4 text

autoscout24.de

Slide 5

Slide 5 text

@x2on Continuous Integration • Tool • Minimize risk & Quality improvement • Automate! • Example: Xcode Bots, Jenkins, TeamCity, Bamboo, ...

Slide 6

Slide 6 text

@x2on Components • Build management • Unit tests • Integration tests • Automatic beta versions

Slide 7

Slide 7 text

@x2on Xcode Bots?

Slide 8

Slide 8 text

@x2on Beta App Internal App Store General Setup CI Server Changes Results Build Agent‘s

Slide 9

Slide 9 text

@x2on Build Unit-Tests Integration-Tests Every Hour Detail Setup Sourcecode Changes Alpha Version Every Hour

Slide 10

Slide 10 text

@x2on Hard & Software Setup • Server: • TeamCity Continuous Integration Server • Build Agents: • Mac Mini’s in 19’’ Racks • Mac OS X 10.9 / Xcode 5 / Homebrew / JDK 7

Slide 11

Slide 11 text

@x2on iOS Setup • Dependencies • CocoaPods • gradle-cocoapods-plugin • Build • xctool

Slide 12

Slide 12 text

@x2on iOS Setup • Tests • xctool • xctool teamcity reporter • Package • xctool • xcodebuild • gradle-hockeyapp-plugin

Slide 13

Slide 13 text

@x2on iOS Tests • Unit Tests: Apple XCTest • Mock: OCMock 3 • View Tests: ios-snapshot-test-case • PNG view rendering / compare • Integration Tests: KIF • Network Mocking: nocilla

Slide 14

Slide 14 text

@x2on XCTest - Assertion • XCTFail • XCTAssertNil • XCTAssertNotNil • XCTAssertTrue | XCTAssertFalse • XCTAssertEqualObjects • XCTAssertEquals • XCTAssertEqualsWithAccuracy

Slide 15

Slide 15 text

@x2on FBSnapshotTestCase • Setup: • pod ‚FBSnapshotTestCase'

Slide 16

Slide 16 text

@x2on FBSnapshotTestCase • Setup: • FB_REFERENCE_IMAGE_DIR

Slide 17

Slide 17 text

@x2on FBSnapshotTestCase

Slide 18

Slide 18 text

@x2on Reference Failed Diff

Slide 19

Slide 19 text

@x2on Mocking • Dummy Objects • Verify calls • OCMock Framework • http://ocmock.org/

Slide 20

Slide 20 text

@x2on Class/Protocol Mock id sample1 = OCMClassMock([Sample class]);! id sample2 = OCMProtocolMock(@protocol(SProtocol));! ! id object = [Sample new];! id sample3 = OCMPartialMock(object);

Slide 21

Slide 21 text

@x2on Stubbing Mock OCMStub([mock someMethod]).andReturn(aObject);! OCMStub([mock someValue]).andReturn(YES);! OCMStub([mock someLong]).andReturn(1); //FAIL! OCMStub([mock someLong]).andReturn(1.0L);! OCMStub([mock someMethod]).andForwardToRealObject();

Slide 22

Slide 22 text

@x2on Verify Mock id sample = OCMClassMock([SomeClass class]);! /* insert your test here */! OCMVerify([mock someMethod]);

Slide 23

Slide 23 text

@x2on Matching arguments Mock OCMStub([mock someMethod:[OCMArg isNil]]);! OCMStub([mock someMethod:[OCMArg isNotNil]]);! OCMStub([mock someMethod:[OCMArg isNotEqual:aValue]]);! OCMStub([mock someMethod:[OCMArg ! 
 ! ! ! ! ! checkWithBlock:^BOOL(id value) 
 ! ! ! ! ! ! ! ! ! ! ! {
 ! ! ! ! ! ! ! ! ! ! ! ! BOOL result;
 !! ! ! ! ! ! ! ! ! ! ! /*…*/
 ! ! ! ! ! ! ! ! ! ! ! ! return result; 
 ! ! ! ! ! ! ! ! ! ! ! }]);

Slide 24

Slide 24 text

@x2on Execute Block - Mock OCMStub(
 ! [mock someMethodWithCompletionBlock:OCMOCK_ANY]
 ! ! ).andDo(^(NSInvocation *invocation) {! ! ! void (^completion)(NSDictionary *someDict, NSError *error);! ! ! [invocation getArgument:&completion atIndex:2];! ! ! completion(@{@“key“:@“value“}, nil);! ! };

Slide 25

Slide 25 text

@x2on xctool xctool 
 ! -workspace DWX-2014-Demo.xcworkspace 
 ! -scheme Build
 ! -sdk iphonesimulator
 ! -destination "platform=iOS Simulator,OS=latest,name=iPhone Retina (4-inch)"
 ! -reporter pretty
 ! -reporter teamcity
 ! clean
 ! test!

Slide 26

Slide 26 text

@x2on xctool reporter • pretty • plain • phabricator • junit • json-stream • json-compilation-database • user-notifications • teamcity

Slide 27

Slide 27 text

@x2on Integration tests • „Automatic click test“ • KIF (Keep It Functional) • Tests in Objective-C • Test-Szenarios & Test-Steps • Accessibility Elements • XCTest Target —> Link App • https://github.com/kif-framework/KIF

Slide 28

Slide 28 text

@x2on KIF [tester enterText:@"[email protected]" intoViewWithAccessibilityLabel:@"Login"];! [tester enterText:@"mypassword" intoViewWithAccessibilityLabel:@"Password"];! [tester tapViewWithAccessibilityLabel:@"Login"];! [tester waitForTappableViewWithAccessibilityLabel:@"My User"];

Slide 29

Slide 29 text

@x2on Nocilla • HTTP Response Mocking • Supports AFNetworking, ASI-HTTP-Request, NSURLSession, NSURLConnection, etc. • https://github.com/luisobo/Nocilla

Slide 30

Slide 30 text

@x2on Nocilla stubRequest(@"GET", @„http://www.google.com");! stubRequest(@"GET", @"^http://(.*?)\\.example\\.com/ test\\.json".regex);! stubRequest(@"GET", @„http:// www.google.com“).andReturn(404);! stubRequest(@"GET", @"https://api.example.com/ test.json").andReturn(201).withHeaders(@{@"Content- Type": @"application/json"}).withBody(@"{\"ok \":true}");

Slide 31

Slide 31 text

@x2on Automatic Alpha Versions • iOS: Enterprise Dev Account • Hockey App • Automatic In-App-Updates • Crash Reports • Usage Statistics

Slide 32

Slide 32 text

Crash Analyzing

Slide 33

Slide 33 text

Crash Analyzing

Slide 34

Slide 34 text

@x2on Questions + Contact • Felix Schulze @x2on • github.com/AutoScout24 • github.com/x2on