Test::Cukes - A BDD Tool inspired by Cucumber

作者:   發佈於:  

Cucumber , the BDD tool, is something that is really brilliant. I wrote Ruby code for my work too and I tried to used this tool with watir. Again, Brilliant.

And turns out there are cucumber implementations in Perl too:

But they don't seem to work seamlessly with TAP-family of test tools. So I crafted Test::Cukes. It allows you to write your module test by defining scenarios first, then map those scenarios into test code:

use Test::More;
use Test::Cukes;

Feature: writing behavior tests
  In order to make me happy
  As a test maniac
  I want to write behavior tests

  Scenario: Hello World
    Given the test program is running
    When it reaches this step
    Then it should pass

Given qr/the test program is running/, sub {

When qr/it reaches this step/, sub {

Then qr/it should pass/, sub {

plan tests => 3;

The scenario text is also output with Test::More::note when you run the test.

I hope this can help making my test files more maintainable. When my code base becomes larger I tended to split them into very small files (so I don't have to count the number of OKs like I'm learning math as a kid). However, maybe they should be written as modules and driven by a higher level logic like the code above.