GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test::Roo::Role(3) User Contributed Perl Documentation Test::Roo::Role(3)

Test::Roo::Role - Composable role for Test::Roo

version 1.004

A testing role:

    # t/lib/MyTestRole.pm
    package MyTestRole;
    use Test::Roo::Role; # loads Moo::Role and Test::More

    requires 'class';

    test 'object creation' => sub {
        my $self = shift;
        require_ok( $self->class );
        my $obj  = new_ok( $self->class );
    };

    1;

This module defines test behaviors as a Moo::Role.

Importing Test::Roo::Role also loads Moo::Role (which gives you strictures with fatal warnings and other goodies).

Importing also loads Test::More. Any import arguments are passed through to Test::More's "import" method.

You can create fixtures with normal Moo syntax. You can even make them lazy if you want and require the composing class to provide the builder:

    has fixture => (
        is => 'lazy'
    );

    requires '_build_fixture';

Because this is a Moo::Role, you can require any method you like, not just builders.

See Moo::Role and Role::Tiny for everything you can do with roles.

You can add method modifiers around the "setup" and "teardown" methods and these will be run before tests begin and after tests finish (respectively).

    before  setup     => sub { ... };

    after   teardown  => sub { ... };

You can also add method modifiers around "each_test", which will be run before and after every individual test. You could use these to prepare or reset a fixture.

    has fixture => ( is => 'lazy, clearer => 1, predicate => 1 );

    after  each_test => sub { shift->clear_fixture };

Roles may also modify "setup", "teardown", and "each_test", so the order that modifiers will be called will depend on when roles are composed. Be careful with "each_test", though, because the global effect may make composition more fragile.

You can call test functions in modifiers. For example, you could confirm that something has been set up or cleaned up.

    before each_test => sub { ok( ! shift->has_fixture ) };

Loading Test::Roo::Role exports a single subroutine into the calling package to declare tests.

    test $label => sub { ... };

The "test" function adds a subtest. The code reference will be called with the test object as its only argument.

Tests are run in the order declared, so the order of tests from roles will depend on when they are composed relative to other test declarations.

David Golden <dagolden@cpan.org>

This software is Copyright (c) 2013 by David Golden.

This is free software, licensed under:

  The Apache License, Version 2.0, January 2004
2014-08-05 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.