1

Hi I'm developing a Wordpress plugin which accesses a couple of API's (Amazon Product API, Flickr, Freebase, Ebay). I've already started writing unit tests for it but I'm still wondering if its really the way to go since it takes a lot of time downloading data from the API primarily because my download speed isn't that fast (around 2 Mb/s max). Currently it takes 2 hours or more to run the whole test suite and sometimes I even reach the API limit and the test won't pass.

Is there a better way of doing this? Perhaps automating the test or even allow me to upload the tests somewhere which has a faster download speed.

Do I really need to be testing methods which access the API to begin with? Can I just make use of a mock data instead of querying the API directly?

Thanks in advance!

  • 2
    In general you would mock the external services you use. Simply store the answers of the services for your tests and than mock the service. – MrSmith42 Sep 20 '13 at 7:12
  • how is that done? – Wern Ancheta Sep 20 '13 at 7:15
  • 1
    I am no php developer, but in general: either use a mocking framework (which supports mokking of services), or write a very simple dummy-service, with the same API as the original service you want to mock, which only waits for your specific test requests and than responses with the prerecorded answers of the original service. – MrSmith42 Sep 20 '13 at 9:47
4

You would provide a facade for each of these APIs, which is essentially a wrapper class. So each of the API functions you are going to use will be wrapped by your own code, which you can then also mock.

This means you would have a AmazonProductAPIWrapper class which directly calls each of the APIs you are going to be consuming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.