blog

Cocoapods for Testing HTTP Interactions

by | Nov 20, 2012 | Developer Blog | 0 comments

Cocoapods logo

When writing code to access resources over HTTP or another protocol it’s great to write some tests to make sure that code is working well, but running them can be a pain when working over a slow connection, with large requests, or when working offline.

Two great open source frameworks available as Cocoapods that make testing HTTP and other NSURLConnection based interactions easier are Nocilla and NSURLConnectionVCR. Interestingly, both projects were inspired by similar testing frameworks for Ruby. Nocilla draws from WebMock and NSURLConnectionVCR from the VCR project.

Nocilla provides a DSL for stubbing HTTP requests and works with the popular AFNetworking and MKNetworkKit frameworks too. An even nicer feature is that it won’t let requests without stubs hit the network and instead will return a 500 error and fail your test.

The NSURLConnectionVCR project takes a different approach and allows you to record the responses of NSURLConnection based requests to a file and then "replay" those results when your tests are run again. Using this approach with a number of recording files should let you test your code against a variety of responses very quickly.

It’s always nice to have some extra testing tools at your disposal and with Cocoapods making them so easy to include in your next OS X or iOS project there’s no excuse not to give them a try!

+ more

Accurate Timing

Accurate Timing

In many tasks we need to do something at given intervals of time. The most obvious ways may not give you the best results. Time? Meh. The most basic tasks that don't have what you might call CPU-scale time requirements can be handled with the usual language and...

read more