Fennec Testing Framework - 1.0 Released

Over the weekend I overhauled my personal project Fennec. Fennec is a testing framework for Perl that was originally meant to solve the shortcomings of Perl's other solutions. This release is a major simplification of Fennec, largely as a nod to the fact that Test::Builder2 will solve a majority of the "results should be objects" problems that Fennec formerly addressed.

Fennec solves the following problems:


  • Forking in tests just plain works

  • Tests files are objects (like Test::Class, but without the separation of test class and test script that runs the class)

  • Tests can be separated into groups that are independently runnable, and can be run in parallel

  • RSPEC and other ways to structure tests are available (Test-Workflow)

  • Better mocking ala Mock-Quick

  • Enhanced (but optional and separately packaged) syntax via Devel::Declare. See Fennec-Declare

  • Single place to load all the most common test packages (More, Warn, Exception) with the ability to customize this list.

  • In a verbose harness, diagnostics messages are coupled with their failing tests.

  • No need to formally end tests (no done_testing(), and test counts are handled automatically)

Here is an example Fennec test:


package MyTest;
use strict;
use warnings;
use Fennec;

tests foo => sub {
ok( 1, 'bar' );
};

tests another => sub {
ok( 1, 'something passed' );
};

tests not_ready => (
todo => "Feature not implemented",
code => sub { ... },
);

tests very_not_ready => (
skip => "These tests will die if run"
code => sub { ... },
);

1;

By default all these groups will be run in parallel, though that can be turned off. In addition, if you have a lot of groups, and the file takes too long to run, you can run individual groups alone. This is very helpful when you make a change to one group in a long-running file. Simply run prove on the file with the FENNEC_TEST environment variable set to either the group name, or any of the line numbers the group covers (making editor integration a breeze).

With Fennec::Declare that can be written in a much nicer syntax:


package MyTest;
use strict;
use warnings;
use Fennec::Declare;

tests foo {
ok( 1, 'bar' );
}

tests another {
ok( 1, 'something passed' );
}

tests not_ready (todo => "Feature not implemented") { ... }

tests very_not_ready (skip => "These tests will die if run") { ... }

1;

With Test::Workflow loaded by default you can also write RSPEC style tests. These too will be run in parallel by default (but only under Fennec, not under Test::Workflow alone)

    describe example => sub {
        my $self = shift;
        my $number = 0;
        my $letter = 'A';

before_all setup => sub { $number = 1 };

before_each letter_up => sub { $letter++ };

# it() is an alias for tests()
it check => sub {
my $self = shift;
is( $letter, 'B', "Letter was incremented" );
is( $number, 2, "number was incremented" );
};

after_each reset => sub { $number = 1 };

after_all teardown => sub {
is( $number, 1, "number is back to 1" );
};

describe nested => sub {
# This nested describe block will inherit before_each and
# after_each from the parent block.
...
};

describe maybe_later => (
todo => "We might get to this",
code => { ... },
);
};

One may notice that the tests are declared with the 'tests' keyword, but never appear to actually be run anywhere. Some may leap to the conclusion that an END block must be in use here.... you would be Wrong! There are no END blocks used in Fennec.

Fennec uses a runner. All test files must be loaded by the runner, and then the runner will run it's tests. In the old Fennec this required writing t/Fennec.t and telling it how to find your tests, this is no longer the case. When you use Fennec it will check to see if the test file has been run directly, if it has it will use exec to re-launch Perl and load the file through the runner.

1 Comment

Looks good, will give it a try. The parallel running feature is nice, I know that in some of my projects I don't run tests often enough because they take too much time (even after migrating some tests to Test::Aggregate). Hope Fennec can reduce test times even more. Parallel running can also uncover some otherwise hidden bugs.

Leave a comment

About Chad 'Exodist' Granum

user-pic I blog about Perl.