1

I'd like to take advantage of the testing classes and methods in Xcode to check the responses I receive from several asynchronous HTTP services requests my app does, in order to see if I receive and parse correctly the expected parameters.

Responses I receive are in JSON format, and my app parses them to create custom objects. I call services by means of an object that makes use of an NSURLConnection connection and implements the NSURLConnectionDelegate protocol to get the responses. I don't find a way to test this, since conforming my XCTestCase class to NSURLConnectionDelegate protocol does not seem to work.

Thanks

AppsDev
  • 12,319
  • 23
  • 93
  • 186

1 Answers1

0

I would suggest you are going about this kind of test incorrectly.

Using live data, and actually performing the fetch over the network isn't really what you are testing. You just want to test your parsing of the returned data.

One approach to this is to use a stubbing framework such as OHHTTPStubs or Nocilla.

In this way you can load JSON files and test your parsing, or you could even test for different conditions such as poor networks, or network errors.

This provides a controlled environment in which to perform your tests and is a much better idea than actually performing the fetch.

Another advantage is that you can write code against those tests while you are commuting and without an internet connection :)

Anorak
  • 3,096
  • 1
  • 14
  • 11
  • Thanks. Actually I'd like to test the complete process, since the response of the services depend on the data I send to them – AppsDev Oct 21 '14 at 12:43
  • And that is something else you can set up in the tests. If you are testing the response that the server sends you for given parameters, then that is a test for the server, and not a __unit test__ as you seem to want to do. – Anorak Oct 21 '14 at 12:55
  • Yes, you are right, what I want is more an integration test... which of the frameworks you reference you'd recommend? – AppsDev Oct 21 '14 at 12:57
  • Either. I've used OHHTTPStubs in the past. – Anorak Oct 21 '14 at 12:58