Fraser Speirs Cocoa and Photos

Posted
10 July 2007 @ 10pm

Tagged
Programming

Add:     

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.


4 Comments

Posted by
Douglas F Shearer
11 July 2007 @ 9am

Are you planning to release this Fraser? I’ve thought of building something similar a few times for testing the flickr.rb framework I have recently been augmenting for my own uses.

Relying on actual calls across a network to Flickr for testing is very slow, and not very reliable in my experience. It’s also not good practice.


Posted by
fraserspeirs
11 July 2007 @ 9am

Yeah, I’ll probably make more information available about it once it’s a bit more complete. Upload emulation is not working properly yet.

It’ll never be a proper product in any sense, though.


Posted by
Douglas F Shearer
11 July 2007 @ 11am

Could prove to be a very useful tool, even without upload emulation.

Keep us updated on your progress, no hurry.


Posted by
Jonathan Wight
15 July 2007 @ 4pm

FYI The code has moved from my privately hosted SVN repository onto google code:

http://code.google.com/p/toxic-public/

ToxicHTTP and ToxicNetwork (which ToxicHTTP depends on) are here: http://toxic-public.googlecode.com/svn/trunk/Frameworks/