TEST2::TOOLS::CLASS(3perl)
β¨ NAME β¨
okay so bestie, this page is all about Test2::Tools::Class β the Test2 implementation of the tools you use for testing classes. it lives in the 3perl section of the Perl manual, and it's literally here to make your class tests slay π
πΈ DESCRIPTION πΈ
so like, these are Test2-based tools for validating classes and objects π§ they're giving similar energy to some of the tools you already know from Test::More, but with a much more consistent interface. no cap. it's the same vibe, just cleaner β the way that a friend who reorganizes your entire closet and somehow it's better performs. obsessed π
π SYNOPSIS π
use Test2::Tools::Class;
isa_ok($CLASS_OR_INSTANCE, $PARENT_CLASS1, $PARENT_CLASS2, ...);
isa_ok($CLASS_OR_INSTANCE, [$PARENT_CLASS1, $PARENT_CLASS2, ...], "Test Name");
can_ok($CLASS_OR_INSTANCE, $METHOD1, $METHOD2, ...);
can_ok($CLASS_OR_INSTANCE, [$METHOD1, $METHOD2, ...], "Test Name");
DOES_ok($CLASS_OR_INSTANCE, $ROLE1, $ROLE2, ...);
DOES_ok($CLASS_OR_INSTANCE, [$ROLE1, $ROLE2, ...], "Test Name");
π¦ EXPORTS π¦
okay periodt β every single sub here is exported by default. you don't have to ask. they just show up. iconic behavior π«Ά
can_ok
can_ok($thing, @methods)can_ok($thing, \@methods, $test_name)
this one checks that $thing has the methods you listed. and when I say $thing, I mean either a class name or a blessed instance β both are valid, both work, no gatekeeping π₯
and the lil plot twist: if the second argument is an arrayref, that arrayref gets used as the list of methods, which frees up the third argument to be the test name. so cute, so organized β¨
isa_ok
isa_ok($thing, @classes)isa_ok($thing, \@classes, $test_name)
this one checks that $thing is or subclasses the classes you named. again, $thing can be a class name or a blessed instance, whatever you got π
same deal as before: second argument being an arrayref means it's the list of classes, and the third argument slides right into the test-name position. the way that arrayrefs are just doing the most and it works π
DOES_ok
DOES_ok($thing, @roles)DOES_ok($thing, \@roles, $test_name)
this one checks that $thing does the roles you listed β class name or blessed instance, both welcome, all are valid π
and yes, the second-argument-arrayref thing applies here too: arrayref = the list of roles, third argument = the test name. three for three, we love consistency π
Note 1: this uses the$class->DOES(...)method β not thedoes()method that Moose provides. do not mix those up bestie, that's a different thing entirely π
Note 2: not all perls have the DOES() method. if you use this on those perls, the test will be skipped. so it won't blow up in your face, it'll just quietly sit out. still worth knowing though π
β SOURCE β
the source code repository for Test2-Suite can be found at:
https://github.com/Test-More/test-more/
go forth and read the source, iykyk π§
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
see:
http://dev.perl.org/licenses/
okay bestie that's literally the whole thing β¨ this was Test2::Tools::Class from perl v5.44.0, dated 2026-10-17, and it ate, no crumbs. now go write some tests and make your classes feel seen π«ΆπΈ
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms