I would think mocking was exactly what you need for unit testing in this situation. If you test code is dependant on actual interaction with FB, it's not really unit testing so much as functional testing -- and that has value too, since it may expose problems that your unit test don't surface, for example because the mocks are incorrect or incomplete.
If you want to test "does this code give the right result for known input, assuming the FB API is working correctly", mock it out; if you want to test if that code works correctly in actual use, and/or you don't want to trust the FB API will work correctly (or as you're expecting), use a different strategy. L. On 2011-05-10, at 9:22 AM, Philip Schweiger wrote: > I've been trying to make unit-testing a more regular part of my work > flow - using qUnit so far. I've found it helpful for developing self- > contained projects, for instance jQuery plug-ins. I'm struggling with > working with third-party APIs, though. > > The specific case is working with Facebook. I do a fair amount of > Facebook projects at work, but I always find working with the API very > frustrating. To reduce my stress level, I'm trying to abstract out a > lot of my frequent calls into my own custom wrapper around their API. > I've been using test-driven-development to lend some structure to my > development. > > Where I run into problems is that since this is a wrapper, a lot of my > code ultimately depends on things completely out of my controls, such > as whether a user is logged-in to Facebook or not. > > Conceptually, I realize that what I really want to test is my code - > not the Facebook API. For instance, I would want to test "if I make > call A when user is logged in, is Condition B returned?" and not "when > I call the FB.login() method, is a session cookie is returned?" > > Since I can't programmatically log-in to Facebook, though, I'm finding > that I need to integrate some manual tester-interaction into my unit > tests. For instance, a page of all the tests I can run without being > logged in, then asking the tester to click a log-in button to proceed > to the next set of tests. > > This hybrid automated/manual testing feels off to me, but maybe that's > just the way you have to do such thing? Any thoughts on this from the > group, either about developing with Facebook JS interactions in > specific, or with third-party APIs in general? I know sometimes the > answer to is to mock your third-party interactions, but when working > so closely with an API, that doesn't seem realistic or appropriate. > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/jsmentors@jsmentors.com/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/jsmentors@googlegroups.com/ > > To unsubscribe from this group, send email to > jsmentors+unsubscr...@googlegroups.com -- Laurie Harper http://laurie.holoweb.net/ -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com