This document discusses testing in iOS applications. It begins by introducing the author and their background. It then discusses reasons for testing like reliability, regression testing, and confidence during refactoring. Potential issues with testing like heavy UI dependence and non-testable code are addressed. The document recommends separating UI and service code for better testability. It demonstrates the Kiwi and OCMock testing frameworks and provides examples of testing classes, dependencies, and private/static methods in an isolated way without heavy mocking. It emphasizes best practices like writing tests first and using version control properly.
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 ?rst (twice), then code :)
? Tests should come ?rst
? Write the failing test, pass the test,
refactor
? Adequate tools can enhance your
testing experience