Test::...s::Most(3pm)

πŸ’– Test::Class::Most(3pm) β€” Test Classes but make it effortless πŸ’–

Okay bestie, so this is the manual page for Test::Class::Most, and no cap it's about to make your test-writing life so much easier. Version? 0.08. Periodt.


🌸 SYNOPSIS 🌸

So like, instead of typing out this whole entire vibe:

use strict;
use warnings;
use Test::Exception 0.88;
use Test::Differences 0.500;
use Test::Deep 0.106;
use Test::Warn 0.11;
use Test::More 0.88;

use parent 'My::Test::Class';

sub some_test : Tests { ... }

You literally just type this:

use Test::Class::Most parent => 'My::Test::Class';

sub some_test : Tests { ... }

Ate. No crumbs. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So when people write test classes with the iconic Test::Class, you always see this at the top of the code:

package Some::Test::Class;

use strict;
use warnings;
use base 'My::Test::Class';
use Test::More;
use Test::Exception;

# and then the tests ...

And honestly? That's a whole lot of boilerplate and the author is not a fan. So now you can just do this:

use Test::Class::Most parent => 'My::Test::Class';

That automatically imports strict and warnings for you. And it also gives you all of the testing goodness from Test::Most. Obsessed. ✨


πŸ’œ CREATING YOUR OWN BASE CLASS πŸ’œ

You probably want to create your own base class for testing. To do this, simply specify no import list:

package My::Test::Class;
use Test::Class::Most; # we now inherit from Test::Class

INIT { Test::Class->runtests }

1;

And then your other classes inherit as normal (well, the way we do it):

package Tests::For::Foo;
use Test::Class::Most parent => 'My::Test::Class';

And you can inherit from those other classes, too:

package Tests::For::Foo::Child;
use Test::Class::Most parent => 'Tests::For::Foo';

And of course, it's quite possible that you're a fan of multiple inheritance, so you can do that, too (the author was soooooo tempted to not allow this, but figured they shouldn't force too many of their personal beliefs on you):

package Tests::For::ISuckAtOO;
use Test::Class::Most parent => [qw/
   Tests::For::Foo
   Tests::For::Bar
   Some::Other::Class::For::Increased::Stupidity
/];

As a side note, it's recommended that even if you don't need test control methods in your base class, put stubs in there:

package My::Test::Class;
use Test::Class::Most; # we now inherit from Test::Class

INIT { Test::Class->runtests }

sub startup  : Tests(startup)  {}
sub setup    : Tests(setup)    {}
sub teardown : Tests(teardown) {}
sub shutdown : Tests(shutdown) {}

1;

This allows developers to always be able to safely call parent test control methods rather than wonder if they are there:

package Tests::For::Customer;
use Test::Class::Most parent => 'My::Test::Class';

sub setup : Tests(setup) {
  my $test = shift;
  $test->next::method; # safe due to stub in base class
  ...
}

Bestie, that's called future-proofing and it's iconic. 🫢


πŸŽ€ ATTRIBUTES πŸŽ€

You can also specify "attributes" which are merely very simple getter/setters.

use Test::Class::Most
  parent      => 'My::Test::Class',
  attributes  => [qw/customer items/],
  is_abstract => 1;

sub setup : Tests(setup) {
  my $test = shift;
  $test->SUPER::setup;
  $test->customer( ... );
  $test->items( ... );
}

sub some_tests : Tests {
  my $test     = shift;
  my $customer = $test->customer;
  ...
}

Here's the vibe check on how they work:

  • If called with no arguments, returns the current value.
  • If called with one argument, sets that argument as the current value.
  • If called with more than one argument, it croaks.
🚨 Bestie, do not try to pass multiple args β€” it will literally croak at you. That's the rule. πŸ’€

🧚 ABSTRACT CLASSES 🧚

You may pass an optional is_abstract parameter in the import list. It takes a boolean value. This value is advisory only and is not inherited. It defaults to false if not provided.

Sometimes you want to identify a test class as "abstract". It may have a bunch of tests, but those should only run for its subclasses. You can pass <is_abstract = 1>> in the import list. Then, to test if a given class or instance of that class is "abstract":

sub dont_run_in_abstract_base_class : Tests {
    my $test = shift;
    return if Test::Class::Most->is_abstract($test);
    ...
}
⚠️ Note that is_abstract is strictly advisory only. You are expected (required) to check the value yourself and take appropriate action. It's not gonna do the work for you, bestie. πŸ™ˆ

We recommend adding the following method to your base class:

sub is_abstract {
    my $test = shift;
    return Test::Class::Most->is_abstract($test);
}

And later in a subclass:

if ( $test->is_abstract ) { ... }

Slay. Now you're abstract-classing like a pro. πŸ‘‘


🌈 EXPORT 🌈

All functions from Test::Most are automatically exported into your namespace. So you get all that testing goodness for free. No extra typing. We love to see it. πŸ’–


⭐ TUTORIAL ⭐

If you're not familiar with using Test::Class, please see the author's tutorial at:

Go read them. They're giving main character energy for your test suite. πŸ“šβœ¨


🌸 AUTHOR 🌸

Curtis "Ovid" Poe, "<ovid at cpan.org>"


πŸ› BUGS πŸ›

Please report any bugs or feature requests to "bug-test-class-most at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Class-Most>.

The author will be notified, and then you'll automatically be notified of progress on your bug as they make changes. Fr fr, that's the system. πŸ’…


🫢 SUPPORT 🫢

You can find documentation for this module with the perldoc command.

perldoc Test::Class::Most

You can also look for information at:

  • RT: CPAN's request tracker

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Class-Most>

  • AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/Test-Class-Most>

  • CPAN Ratings

<http://cpanratings.perl.org/d/Test-Class-Most>

  • Search CPAN

<http://search.cpan.org/dist/Test-Class-Most/>


πŸ‘€ SEE ALSO πŸ‘€

  • Test::Class β€” xUnit-style testing in Perl
  • Test::Most β€” The most popular CPAN test modules bundled into one module.
  • Modern::Perl β€” "I stole this code. Thanks chromatic!" (author's words, not mine 😭)

πŸ’œ ACKNOWLEDGEMENTS πŸ’œ

Thanks to Adrian Howard for Test::Class, Adam Kennedy for maintaining it and chromatic for Modern::Perl. Icons only. πŸ‘‘


Copyright 2010 Curtis "Ovid" Poe, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


And that's the whole manual, bestie! This page is from perl v5.42.0, dated 2015-04-14, and it's the Test::...s::Most(3pm) manual. Now go write some iconic tests. πŸ’…βœ¨πŸ”₯
πŸ“¦ where this page comes from