Emulating Flickr

I've been working on FlickrExport 3 for a couple of weeks now and one of the things I started off doing was building tools to make testing easier and more predictable.

Unit testing using Xcode's built-in framework remains a pain in the buttocks. Given the large amount of asynchronous NSURLConnection code used in FlickrExport, all the test cases exit before the results arrive. What I've been working on isn't a replacement for unit testing, but it's a tool that makes repeatable Flickr testing significantly faster and easier.

The trick is basically to replace Flickr :-)

I wrote a small app, using Jon Wight's nifty ToxicHTTP framework, that listens on localhost:8080. It parses calls to the Flickr REST endpoint, then looks for a file in a particular directory with the name of the method and returns the contents of that file. It's extremely useful, because it lets me have several different scenarios of simulated 'Flickr' behaviour and have the fake Flickr server respond identically every time. As you might expect, it's also significantly faster to test uploading to localhost than to Flickr!

The idea for this came from a conversation with David Masters at WWDC. I just wrote it in Cocoa, because that's what I do, but similar ideas could probably be knocked together in PHP in half an hour.

If you're working with a remote service that you don't control, consider taking them out of the loop. Just be sure that your emulator remains faithful to the actual deployed service.