This document discusses testing in iOS applications. It explains why testing is important for reliability, preventing regressions, and allowing confidence during refactoring. Some challenges to testing include heavy dependence on UI code and non-testable code. The document recommends separating UI and service interaction code to make it more testable. It introduces the Kiwi and OCMock testing frameworks for iOS and provides examples of writing tests using these frameworks. It also discusses how to test private and static methods as well as isolate dependencies through mocking. The document emphasizes that best practices for testing apply to mobile development as well.
24. Test if calls dep methods
1. Create a mock dependency
2. Inject it
3. Call the method
4. Verify
25. Test dependency
// Create the tested object and mock to exchange part of the functionality
viewController = [ViewController new];
mockController = [OCMockObject partialMockForObject:viewController];
// Create the mock and change implementation to return our class
id serviceMock = [OCMockObject mockForClass:[InterwebzService class]];
[[[mockController stub] andReturn:serviceMock] service];
// Define expectations
[[serviceMock expect] downloadTweetsJSONWithSuccessBlock:[OCMArg any]];
// Run the tested method
[viewController tweetsButtonTapped:nil];
// Verify - throws exception on failure
[mockController verify];
26. Testing one layer
• Isolate dependencies
• Objective-C is highly dynamic - we can
change implementations of private
methods or static methods
• We can avoid IoC containers for testing
32. Problems of „mobile devs”
• Pushing code with failing tests
• Lot’s of hacking together
• Weak knowledge of VCS tools - merge
nightmares
33. Ending thoughts
• Think first (twice), then code :)
• Tests should come first
• Write the failing test, pass the test,
refactor
• Adequate tools can enhance your
testing experience