API Client TDD with Mocked Responses


API Client TDD with Mocked Responses
In parts one and two , we built some very basic functionality and used TDD with PHPUnit to make sure our classes are well tested. We also learned how to test an abstract class in order to make sure its concrete methods worked. Now, let’s continue building our library.

Catch up
I took the liberty of implementing the functionality and the test for the abstract API class’ constructor, requiring the URL to be passed in. It’s very similar to what we did with the Diffbot and DiffbotTest classes.

I also added some more simple methods, and testing of the different API instantiations and custom fields for the APIs into the mix with dynamic setters and getters using __call . This seemed like too menial work to bother you with as it’s highly repetitive and ultimately futile at this point, but if you’re curious, please leave a comment below and we’ll go through part2-end > part3-start differences in another post – you can even diff the various files and ask about specific differences in the forums, I’d be happy to answer them to the best of my knowledge, and also take some advice regarding their design. Additionally, I have moved the “runInSeparateProcess” directive from the entire DiffbotTest class to just the test that needs an empty static class, which reduced the duration of the entire testing phase to mere seconds.

If you’re just now joining us, please download the part 3 start branch and catch up.

Data Mocking
We mentioned before we would be data mocking in this part. This might sound more confusing than it is, so allow me to clarify. When we request a URL through Diffbot, we expect a certain result. Like, requesting a specific Amazon product, we expect to get the parsed values for that product. However, if we rely on this live data in our tests, we face two problems:

The tests become slower by X, where X is the time required to fetch the data from Amazon
The data can change and break our tests. Suddenly, some information our tests relied upon before can break due to different values being returned.
Because of this, it’s best if we cache the entire response to a given API call offline – headers and all – and use it to fake a response to Guzzle (functionality Guzzle has built in). This way, we can feed Diffbot a fake every time during tests and make sure it gets the same data, thereby giving us consistent results. Matthew Setter wrote about data mocking with Guzzle and PHPUnit before here , if you’d like to take a look.

To get to the testing level we need, we’ll be faking the data that Diffbot returns. Doesn’t this mean that we aren’t effectively testing Diffbot itself but only our ability to parse the data? Exactly, it does. It’s not on us to test Diffbot – Diffbot’s crew does that. What we’re testing here is the ability to initiate API calls and parse the data they return – that’s all.

Continue reading % API Client TDD with Mocked Responses %

http://ift.tt/1viGoty

Daily Digest: VS2013 Online, TDD in ASP.NET MVC, Agile and Quality Assurance, and more…


good2know_banner

Microsoft Announces the Launch of Visual Studio 2013 Online: 
View article…

Microsoft Announces New Server and Cloud Pricing for Enterprise Users: 
View article…


good2read_banner

Test Driven Development in Asp.Net MVC Architecture: 
Unit test cases can be written precisely to ensure code coverage of more than 90% without any complexities. Read on to learn more about test driven development (TDD) with Asp.Net MVC applications.
View article…

True Quality Assurance in an Agile World: 
Quality Assurance is not just about testing a system. The role of QA on an agile team is much greater than that, elevating the QA engineer to a god among men.
View article…

Meter and Autoscale Multi-Tenant Applications in Windows Azure: 
In the second of a two-part series, Bruno Terkaly and Ricardo Villalobos continue their discussion of multi-tenant architecture by exploring metering and autoscaling of resources.
View article…


good2watch_banner

Meet WACEL: 
Introducting WACEL – Windows Azure Cache Extension Library.
View article…


Follow-me-on-twitter

Daily Digest: 30 days of TDD, VS2013 new features, Azure BizTalk Services and more…


good2know_banner

Microsoft cuts first-generation Surface Pro prices by $100:
Attention, bargain hunters and those who don’t need to be on the cutting edge: The 64GB and 128GB versions of the older tablets now cost $699 and $799, respectively
View article…

Google breaks old promise by working on search banner ads:
Google is testing banner ads in search results, apparently reneging on a 2005 promise by Marissa Mayer to never run them.
View article…

Internet begins its move beyond .com, .net, and .edu:
The Internet’s address books just got the first four new generic top-level domains, but they won’t go live on the Net until trademark holders get a chance to stake their claims.
View article…


good2read_banner

What Does an Architect Do in an Agile Shop?:
If you’re wondering what a software architect does in an agile development environment, you’re not alone. Mark J. Balbes shares what he does and how it all comes together in better code.
View article…

Scheduler API in Windows 8.1 and Visual Studio 2013:
Learn how to manage and schedule tasks or jobs in Windows 8.1 using The New Scheduler API, which forms part of WinJS.Utilities and is brand new.
View article…

Introduction to Windows Store App Development for Android Programmers:
This session will help developers leverage their existing Android concepts to build Windows Store apps.
View article…

Working with the New Point Of Service APIs in Windows 8.1:
Windows 8.1 introduces first class support for Point of Services (POS) devices like barcode scanners and magnetic stripe readers. Read on to learn the basics of the Point of Service APIs and how to use them in a Windows 8.1 application.
View article…


good2watch_banner

Windows Azure BizTalk Services:
Kris Iverson discusses some of the different models and talked about the differences between them and what 3D printing support in Windows means for users and developers.
View article…

What’s New in the Visual Studio 2013 IDE:
With Visual Studio 2013 it just gets better when your IDE is connected. New roaming support, notifications and a new Visual Studio Updates experience means you get fixes and features sooner.
View article…


Follow-me-on-twitter