News Feed
Sections




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

NetTuts.com:
Expressive Tests with Hamcrest
December 06, 2012 @ 12:25:12

On the NetTuts.com site today there's a new tutorial introducing the Hamcrest validation matchers and how to use them in your PHPUnit testing to enhance both the readability and functionality of the assertions.

Hamcrest is a set of matchers for writing more expressive code. It just so happens that these matchers are especially useful when writing tests. In this article, we'll look at Hamcrest for PHP. [...] Hamcret's expressiveness originated with JMock, but it wasn't until the addition of the unique assertThat() method that it was refactored into a self-contained library and independently usable in testing frameworks.

He talks about the "generations" of unit testing tools, a division based on their assertion functionality - simple, exact or using matchers. Installation instructions via PEAR are included (though there's also a composer package for it too) as well as code for an example test. More samples are given for comparing things like numeric values, strings and setting up inclusions and exclusions with the anyOf/noneOf matchers.

0 comments voice your opinion now!
hamcrest unittest assertion tutorial library


blog comments powered by Disqus

Similar Posts

Inviqa techPortal: Functionally Testing You Application Using Mink

Zurab Davitiani: PHP Sessions in Erlang Mnesia

DevChix: Getting started with YUI's Connection Manager in Rails and PHP

Jakub Zalas' Blog: Mocking Symfony Container services in Behat scenarios with Mockery

Mike Naberezny's Blog: Wrapping PHP Functions for Testability


Community Events





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


podcast deployment tips introduction list bugfix language conference symfony api zendserver community series release library interview voicesoftheelephpant laravel developer framework

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