Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automated Testing with iOS

Automated Testing with iOS

The talk gives an overview of automated testing with iOS. It discusses the issues of project construction, unit testing, view testing, integration testing, automated distribution of betas and the automated app build with a continuous integration system. Particular, it will address the pitfalls and best practices from experience gained during development at AutoScout24.

Felix Schulze

July 14, 2014
Tweet

More Decks by Felix Schulze

Other Decks in Technology

Transcript

  1. @x2on Continuous Integration • Tool • Minimize risk & Quality

    improvement • Automate! • Example: Xcode Bots, Jenkins, TeamCity, Bamboo, ...
  2. @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
  3. @x2on iOS Setup • Tests • xctool • xctool teamcity

    reporter • Package • xctool • xcodebuild • gradle-hockeyapp-plugin
  4. @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
  5. @x2on XCTest - Assertion • XCTFail • XCTAssertNil • XCTAssertNotNil

    • XCTAssertTrue | XCTAssertFalse • XCTAssertEqualObjects • XCTAssertEquals • XCTAssertEqualsWithAccuracy
  6. @x2on Class/Protocol Mock id sample1 = OCMClassMock([Sample class]);! id sample2

    = OCMProtocolMock(@protocol(SProtocol));! ! id object = [Sample new];! id sample3 = OCMPartialMock(object);
  7. @x2on Verify Mock id sample = OCMClassMock([SomeClass class]);! /* insert

    your test here */! OCMVerify([mock someMethod]);
  8. @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; 
 ! ! ! ! ! ! ! ! ! ! ! }]);
  9. @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);! ! };
  10. @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!
  11. @x2on xctool reporter • pretty • plain • phabricator •

    junit • json-stream • json-compilation-database • user-notifications • teamcity
  12. @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
  13. @x2on Nocilla • HTTP Response Mocking • Supports AFNetworking, ASI-HTTP-Request,

    NSURLSession, NSURLConnection, etc. • https://github.com/luisobo/Nocilla
  14. @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}");
  15. @x2on Automatic Alpha Versions • iOS: Enterprise Dev Account •

    Hockey App • Automatic In-App-Updates • Crash Reports • Usage Statistics