News Feed
Sections




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

Codeception Blog:
BDD Approach to Unit Testing with Codeception
February 15, 2012 @ 10:22:19

Michael Bodnarchuk passed along a new post on the Codeception site about using the tool in a behavior-driven testing methodology. This post is a follow up to their previous one covering acceptance testing.

With BDD approach in Codeception, any test, even the unit test, is written as a scenario. By this scenario you declare what you are doing and what results you expect to see. In traditional xUnit scheme your test is just a piece of code that uses the method being tested. This piece of code becomes a mess when you test complex units depending on other classes or when you need to check data in a database, etc. Codeception always keeps your unit tests simple and readable.

Sample code is included for a simple "User" model class that needs testing. Since the class only directly contains a "create" method, that's all they test - setting up a new user, calling "create" and checking to see if they exist. This basic test is modified slightly to handle the exceptions that might be thrown from the "create" method (when something happens like the user already exists) and checking the user's default role assertions. Plus, using this plugin for DocBlox, you can generate readable test documentation directly from the code.

0 comments voice your opinion now!
bdd unittest tutorial docblox plugin


blog comments powered by Disqus

Similar Posts

Gonzalo Ayuso: Handling several DBALs in Symfony2 through the Dependency Injection with PHP

Greg Beaver's Blog: Code Coverage Reporting using PEAR, PEAR2, phar, and sqlite3

QaFoo.com: Code Coverage with Behat

PHPInfo: Add Sting to PHP Apps with WASP Patterns

DevShed: Performing Basic Tasks with MySQL 4.1 and Above, using mysqli with PHP 5


Community Events





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


version application package install introduction series podcast tool composer symfony laravel framework opinion release interview security library language voicesoftheelephpant community

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