News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Chris Hartjes' Blog:
Simple API Testing Using Behat
February 27, 2012 @ 10:09:18

Chris Hartjes has taken some of his first steps to testing a web service with the help of the Behat BDD testing framework. In this new post he shares some of that knowledge and a bit of code to help guide you if you'd like to get started yourself.

I have been trying to push my JavaScript skills lately by first playing around with Node.js to get a feel for event-driven server-side coding and by trying to build something semi-useful using Knockout. [...] After working with PHPUnit's "assert that the result matches expectations" philosophy, switching to using a behavioural approach has changed how I decide to approach actually testing something.

He shows how to define a "scenario" in a more recognizable sort of English. His example is testing a web service to ensure of a few things:

  • the response is JSON
  • it contains at least one transaction
  • the first transaction has an ID, contains two teams and has a description

Included in the post is the resulting Behat test code (generated and modified with his testing details) and an example of the execution of the test.

I think that the BDD approach maps better to a results-oriented methodology when it comes to testing: you are using real-life scenarios to make sure that you are getting back the results you are expecting. In the end. that is still the goal of testing.
0 comments voice your opinion now!
simple api test behaviordriven behat example slim framework


blog comments powered by Disqus

Similar Posts

Matt Frost: Using Selenium2 with PHPUnit

Chris Hartjes' Blog: The Devilís In The Details (or, Handling Sequences in Postgres in CakePHP)

IBM developerWorks: Intro to MVC Programming with Agavi, Part 1: Open a whole new world with Agavi

Shunro Dozono's Blog: Seven free layout templates for CakePHP

Script-Tutorials.com: Vimeo API - OAuth and Upload Example


Community Events





Don't see your event here?
Let us know!


laravel api opinion introduction language list deployment series voicesoftheelephpant framework community symfony install podcast release package interview tips library bugfix

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework