// I need to

ModernizeUpgrade without breaking it RescueFix what someone else started Build NewTurn an idea into a product Reach More PeopleGet found, get used, include everyone

// Company

Case StudiesExpertiseAbout + CareersResourcesContact Book a call →
≡articleRescue

Cocoapods for Testing HTTP Interactions

Test iOS HTTP code offline or over slow connections with Nocilla and NSURLConnectionVCR, two CocoaPods inspired by Ruby's WebMock and VCR.

Art+Logic Nov 20, 20121 min read

From the Art+Logic archive · written in 2012. The tools may have moved on; the thinking still holds.

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!

keep going

More to explore in Rescue.

All Rescue resources →
let's talk

Got a problem like this one?

Tell us what's stuck. A real person replies within one business day.

Talk to our team →

Talk to people who know software, not a sales script.

Your first call is with Aja, our VP of Sales. He'll help make sure you're solving the right problem. Here's what you'll cover together:

  1. What you're trying to accomplish

    The business goal first, then the technology.

  2. Possible approaches

    And the tradeoffs of each, in plain language.

  3. Risks you may not have considered

    Technical and business, before they cost you.

  4. Whether AI changes the math

    What's practical, and what's just hype for your project.

  5. Sensible next steps

    Even if the right next step is not us.

book-a-call.ics

Loading the scheduler…

Open the booking page →

Some problems are easier to explain in writing. Send us a few lines about what you're working on, and we'll reply within one business day. Helpful to include:

  1. What the software does, or should do
  2. What's stuck, or what's worrying you
  3. Any deadline or budget you have in mind
note.md

Loading the form…