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

NetTuts.com:
Expressive Tests with Hamcrest
Dec 06, 2012 @ 18: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.

tagged: hamcrest unittest assertion tutorial library

Link:

Sebastian Bergmann's Blog:
Getting Started with Hamcrest
Jan 09, 2008 @ 16:23:00

Following up on the start of his port of the Hamcrest (a library of "matchers") functionality over to PHP, Sebastian Bergmann has posted the getting started guide to show you how to use it with the popular PHPUnit unit testing software.

There are a number of situations where matchers are invaluble, such as UI validation, or data filtering, but it is in the area of writing flexible tests that matchers are most commonly used.

His example that checks to see if one object is equal to another object. The Hamcrest matcher allows for a "assertThat" method making it easier to create and use pre-existing unit testing assertions.

He also includes a list of some of the most common matchers broken up into groups of core, logical, object, number and text.

tagged: hamcrest matcher library gettingstarted tutorial assert hamcrest matcher library gettingstarted tutorial assert

Link:

Sebastian Bergmann's Blog:
Getting Started with Hamcrest
Jan 09, 2008 @ 16:23:00

Following up on the start of his port of the Hamcrest (a library of "matchers") functionality over to PHP, Sebastian Bergmann has posted the getting started guide to show you how to use it with the popular PHPUnit unit testing software.

There are a number of situations where matchers are invaluble, such as UI validation, or data filtering, but it is in the area of writing flexible tests that matchers are most commonly used.

His example that checks to see if one object is equal to another object. The Hamcrest matcher allows for a "assertThat" method making it easier to create and use pre-existing unit testing assertions.

He also includes a list of some of the most common matchers broken up into groups of core, logical, object, number and text.

tagged: hamcrest matcher library gettingstarted tutorial assert hamcrest matcher library gettingstarted tutorial assert

Link:

Sebastian Bergmann's Blog:
Hamcrest
Jan 01, 2008 @ 20:16:00

In a new post to his blog, Sebastian Bergmann mentions a new effort he's undertaken - the porting of the Hamcrest library of matcher objects to PHP.

I have begun to port Hamcrest, which provides a library of matcher objects (also known as constraints or predicates) allowing "match" rules to be defined declaratively, to be used in other frameworks. Typical scenarios include testing frameworks, mocking libraries and UI validation rules, to PHP.

The hamcrest-php project compliments other current hamcrest-related projects and his ultimate goal is to make it available to the PHPUnit testing community (as well as with the PHPMock effort).

tagged: hamcrest phpunit matcher constraint object phpmock port hamcrest phpunit matcher constraint object phpmock port

Link:

Sebastian Bergmann's Blog:
Hamcrest
Jan 01, 2008 @ 20:16:00

In a new post to his blog, Sebastian Bergmann mentions a new effort he's undertaken - the porting of the Hamcrest library of matcher objects to PHP.

I have begun to port Hamcrest, which provides a library of matcher objects (also known as constraints or predicates) allowing "match" rules to be defined declaratively, to be used in other frameworks. Typical scenarios include testing frameworks, mocking libraries and UI validation rules, to PHP.

The hamcrest-php project compliments other current hamcrest-related projects and his ultimate goal is to make it available to the PHPUnit testing community (as well as with the PHPMock effort).

tagged: hamcrest phpunit matcher constraint object phpmock port hamcrest phpunit matcher constraint object phpmock port

Link:


Trending Topics: