--- On Tue, 28/9/10, Spiros Denaxas <s.dena...@gmail.com> wrote: > From: Spiros Denaxas <s.dena...@gmail.com>
> I am venturing off to write a module which will act as a > wrapper > around an online API provided by a third party. I am trying > to plan > ahead of time how the tests for it will work. > > On the one hand, I am thinking that creating a test with > the module > that accesses the actual online service might be the most > accurate way > of testing things, on the other hand I am not sure if this > is the > "canonical" way of doing things. I have done some > reading around and > some people suggested that instead of hitting the actual > online source > one should mock the output it returns tand take it from > there. In the > past, I have actually written tests to hit the live server > but I am > wondering if there's another way to this. > > Is there any standard way for this sort of thing? There are no standards that I know of because different situations can call for different responses. However, be very careful about just mocking everything. If you do and their API changes, you'll find yourself with passing tests for code which does not work. Contact the people supplying the API (or read their docs carefully) and find out if you can interrogate for a version and what guarantees they provide for said version. Don't allow mocks if the version changes unless you can't connect. With that, you might offer people the option of connecting live, but also making it clear that you only support version X. Again, there are numerous strategies you can take but the right one(s) will depend on your needs. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://blogs.perl.org/users/ovid/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6