This document discusses OHHTTPStubs, a library for stubbing network requests in iOS unit and integration tests. It provides examples of how to use OHHTTPStubs to stub requests and responses using files, JSON objects or code. The document also presents two use cases - refactoring existing network code to make it testable, and stubbing requests for features that depend on not-yet-implemented web services, to allow development and testing ahead of server integration.
15. Our context
• Two network modules:
1 legacy with NSURLConnection
1 new with AFNetworking
• Server and App code with little or no
documentation
• No tests
16. Can’t we just rewrite the
old code and be done
with it ?
Of course.
But what about regressions?
17. But we cannot write tests on
the old network code?!
• new API is different (block callbacks vs delegation
to objects)
• network logic is mostly inside controllers
19. What do we do in a test?
• Given a set of inputs
• When operating on this set
• Then check the outputs
20. How do we test this?
Controller
Request
Manual Object
Mapping
Legacy Network Module
NSURLConnection OHHTTPStubs
• check network
call
• return expected
JSON data
Check mappingTest call
21. How do we do this?
1.Gather existing requests with corresponding
responses
2.Use OHHTTPStubs to stub the requests
3.Implement tests on existing code
4.Refactor!
26. How can we achieve this?
• Specify the web service entry point precisely
(parameters and output data)
• Stub the request using this specification
• Develop the feature (with its tests!)
27. How can we achieve this?
OHHTTPStubs
JSON
Files
NSURLConnection NSURLSession
28. What we have used
JSON configuration files
}Stubbed
request
}JSON
stub