Test::Roo::Role(3pm)
π NAME π
Test::Roo::Role β a composable role for Test::Roo π¦
It's the Perl module you're reading about rn, from the User Contributed Perl Documentation crew, and bestie it is so handy.
β¨ VERSION β¨
version 1.004 π
πΈ SYNOPSIS πΈ
A testing role, ok so here's the whole vibe:
# 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;
that's it that's the whole file, 1; at the end because Perl said so π
π«Ά DESCRIPTION π«Ά
This module defines test behaviors as a Moo::Role. That's the whole thing. That's what it does. And it does it iconically.
π USAGE π
Importing Test::Roo::Role also loads Moo::Role β which gives you strictures with fatal warnings and a bunch of other goodies, no extra charge, we love a bundle π
Importing also loads Test::More. Any import arguments you pass get passed straight through to Test::More's "import" method. No notes, it just forwards them.
π Creating and requiring fixtures
You can create fixtures with normal Moo syntax. You can even make them lazy if that's your mood and require the composing class to provide the builder:
has fixture => (
is => 'lazy'
);
requires '_build_fixture';
And because this is a Moo::Role, you can requires any method you like, not just builders. Go off.
See Moo::Role and Role::Tiny for everything you can do with roles. Like, everything. π
π Setup and teardown
You can add method modifiers around the "setup" and "teardown" methods and these will be run before tests begin and after tests finish (respectively). Yes. 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. Use these to prepare or reset a fixture, whatever your heart desires:
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. So like, be aware of your ordering, it's giving β¨schedulingβ¨.
Be careful with "each_test", though, because the global effect may make composition more fragile. π Not me warning you about fragile composition bestie, but here we are.
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 ) };
look at that. a whole vibe check for your fixture. π
π EXPORTED FUNCTIONS π
Loading Test::Roo::Role exports a single subroutine into the calling package to declare tests. One. Uno. A single one. Slay.
π test
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. Order matters, bestie. It always does. π
π¦ AUTHOR π¦
David Golden <dagolden@cpan.org> β thank you for your service king π«Ά
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
okay and that's the whole page!! this was Test::Roo::Role, version 1.004, perl v5.34.0, dated 2022-06-28, from the User Contributed Perl Documentation collection. go forth and compose your roles, you're gonna do amazing, ily, bye πβ¨π
π¦ where this page comes from
- debian bookworm: libtest-roo-perl 1.004-2 Β· Apache-2.0
- debian trixie: libtest-roo-perl 1.004-2 Β· Apache-2.0
- ubuntu noble: libtest-roo-perl 1.004-2 Β· Apache-2.0
- ubuntu resolute: libtest-roo-perl 1.004-2 Β· Apache-2.0
- ubuntu stonking: libtest-roo-perl 1.004-2 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms