tags:

views:

85

answers:

1

I'm using a twitter gem which basically accesses twitter and lets me grab tweets, timeline etc. Its really good but I have a lot of my code that uses the stuff it returns and I need to test it. The things the gem returns aren't exactly simple strings, there pretty complex objects (scary as well) so im left scratching my head.

So basically I'm looking for an answer, book, blog, open-source project that can show me the rights and wrongs of testing around external services.

answers that are either not language centric or ruby/rails centric would most greatly be appreciated.

+3  A: 

What you are really talking about are two different kinds of testing that you would want to accomplish - unit tests and integration tests.

Unit tests will test the validity of the methods, independently of any external data. You should look into some sort of mocking framework, based on whatever language it is that you are using. You are basically looking to say, with the tests, something equivalent to "if these assumptions are qualified, then this test should yield..." The making framework will define your assumptions, in terms of saying that certain classes/objects are set in a particular way and can be assumed to be valid. These are the tests that will not rely on Twitter being alive, or the third part library/API being responsive.

Integration tests will perform tests live against the data source, consuming the library/API to perform actual actions. Where it gets tricky, since you are using a third party service, is in writing out to the service (i.e. if you are creating new Tweets). If you are, you could always create an account on Twitter that could be used just for write operations. Generally, if you were testing against a local database - for example - you could then, instead, use transactions to test similar operations; rolling back the transactions instead of committing them.

Here are a couple of non-language specific, high-level definitions:

I am from a .NET stack, so I won't pretend to know much about Ruby. A quick Google search, though, did reveal the following:

joseph.ferris
thanks joseph for your reply. Ive used mocha before but was wondering how to use it properly, pitfalls etc. Live testing would be nice, having to reset my twitter account each time would be a pain, i dont belive you can do it programmatically.
adam