Pins this version in aipm.package.json and aipm-lock.json.
aipm add @affaan-m/perl-testing@1.0.0
Without project tracking
Writes the skill files only. Add --no-init to skip aipm.package.json and the lockfile.
aipm add @affaan-m/perl-testing@1.0.0 --no-init
How to use
Install the skill above, then run this in your AI tool:
/perl-testing <your description>
About
Comprehensive testing strategies for Perl applications using Test2::V0, Test::More, prove, and TDD methodology.
Source
What gets added to your project
Preview every file this package writes on install before you run the command above.
Summary
Perl testing patterns using Test2::V0, Test::More, prove runner, mocking, coverage with Devel::Cover, and TDD methodology. Use when writing Perl tests with Test2::V0 or Test::More, or measuring coverage.
Skill instructions
Perl Testing Patterns
Comprehensive testing strategies for Perl applications using Test2::V0, Test::More, prove, and TDD methodology.
When to Activate
Writing new Perl code (follow TDD: red, green, refactor)
Designing test suites for Perl modules or applications
Reviewing Perl test coverage
Setting up Perl testing infrastructure
Migrating tests from Test::More to Test2::V0
Debugging failing Perl tests
TDD Workflow
Always follow the RED-GREEN-REFACTOR cycle.
perl
# Step 1: RED — Write a failing test# t/unit/calculator.tusev5.36;
use Test2::V0;
use lib 'lib';
use Calculator;
subtest 'addition' => sub{
my$calc = Calculator->new;
is($calc->add(2, 3), 5, 'adds two numbers');
is($calc->add(-1, 1), 0, 'handles negatives');
};
done_testing;
# Step 2: GREEN — Write minimal implementation# lib/Calculator.pmpackage Calculator;
usev5.36;
use Moo;
subadd($self, $a, $b) {
return$a + $b;
}
1;
# Step 3: REFACTOR — Improve while tests stay green# Run: prove -lv t/unit/calculator.t
Test::More Fundamentals
The standard Perl testing module — widely used, ships with core.
Basic Assertions
perl
usev5.36;
use Test::More;
# Plan upfront or use done_testing# plan tests => 5; # Fixed plan (optional)# Equality
is($result, 42, 'returns correct value');
isnt($result, 0, 'not zero');
# Boolean
ok($user->is_active, 'user is active');
ok(!$user->is_banned, 'user is not banned');
# Deep comparison
is_deeply(
$got,
{ name =>'Alice', roles => ['admin'] },
'returns expected structure'
);
# Pattern matching
like($error, qr/not found/i, 'error mentions not found');
unlike($output, qr/password/, 'output hides password');
# Type check
isa_ok($obj, 'MyApp::User');
can_ok($obj, 'save', 'delete');
done_testing;
usev5.36;
use Test2::V0;
# Test that code dies
like(
dies { divide(10, 0) },
qr/Division by zero/,
'dies on division by zero'
);
# Test that code lives
ok(lives { divide(10, 2) }, 'division succeeds') or note($@);
# Combined pattern
subtest 'error handling' => sub{
ok(lives { parse_config('valid.json') }, 'valid config parses');
like(
dies { parse_config('missing.json') },
qr/Cannot open/,
'missing file dies with message'
);
};
done_testing;
# Run all tests
prove -l t/
# Verbose output
prove -lv t/
# Run specific test
prove -lv t/unit/user.t
# Recursive search
prove -lr t/
# Parallel execution (8 jobs)
prove -lr -j8 t/
# Run only failing tests from last run
prove -l --state=failed t/
# Colored output with timer
prove -l --color --timer t/
# TAP output for CI
prove -l --formatter TAP::Formatter::JUnit t/ > results.xml
Place reusable helpers in t/lib/TestHelper.pm and load with use lib 't/lib'. Export factory functions like create_test_db(), create_temp_dir(), and fixture_path() via Exporter.
Mocking
Test::MockModule
perl
usev5.36;
use Test2::V0;
use Test::MockModule;
subtest 'mock external API' => sub{
my$mock = Test::MockModule->new('MyApp::API');
# Good: Mock returns controlled data$mock->mock(fetch_user =>sub ($self, $id) {
return { id =>$id, name =>'Mock User', email =>'mock@test.com' };
});
my$api = MyApp::API->new;
my$user = $api->fetch_user(42);
is($user->{name}, 'Mock User', 'returns mocked user');
# Verify call countmy$call_count = 0;
$mock->mock(fetch_user =>sub{ $call_count++; return {} });
$api->fetch_user(1);
$api->fetch_user(2);
is($call_count, 2, 'fetch_user called twice');
# Mock is automatically restored when $mock goes out of scope
};
# Bad: Monkey-patching without restoration# *MyApp::API::fetch_user = sub { ... }; # NEVER — leaks across tests
For lightweight mock objects, use Test::MockObject to create injectable test doubles with ->mock() and verify calls with ->called_ok().
Coverage with Devel::Cover
Running Coverage
bash
# Basic coverage report
cover -test# Or step by step
perl -MDevel::Cover -Ilib t/unit/user.t
cover
# HTML report
cover -report html
open cover_db/coverage.html
# Specific thresholds
cover -test -report text | grep 'Total'# CI-friendly: fail under threshold
cover -test && cover -report text -select'^lib/' \
| perl -ne 'if (/Total.*?(\d+\.\d+)/) { exit 1 if $1 < 80 }'
Integration Testing
Use in-memory SQLite for database tests, mock HTTP::Tiny for API tests.
perl
usev5.36;
use Test2::V0;
use DBI;
subtest 'database integration' => sub{
my$dbh = DBI->connect('dbi:SQLite:dbname=:memory:', '', '', {
RaiseError =>1,
});
$dbh->do('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
$dbh->prepare('INSERT INTO users (name) VALUES (?)')->execute('Alice');
my$row = $dbh->selectrow_hashref('SELECT * FROM users WHERE name = ?', undef, 'Alice');
is($row->{name}, 'Alice', 'inserted and retrieved user');
};
done_testing;
Best Practices
DO
Follow TDD: Write tests before implementation (red-green-refactor)
Use Test2::V0: Modern assertions, better diagnostics
Use subtests: Group related assertions, isolate state
Mock external dependencies: Network, database, file system
Use prove -l: Always include lib/ in @INC
Name tests clearly: 'user login with invalid password fails'
Test edge cases: Empty strings, undef, zero, boundary values
Aim for 80%+ coverage: Focus on business logic paths
Keep tests fast: Mock I/O, use in-memory databases
DON'T
Don't test implementation: Test behavior and output, not internals
Don't share state between subtests: Each subtest should be independent
Don't skip done_testing: Ensures all planned tests ran
Don't over-mock: Mock boundaries only, not the code under test
Don't use Test::More for new projects: Prefer Test2::V0
Don't ignore test failures: All tests must pass before merge
Don't test CPAN modules: Trust libraries to work correctly
Test::MockModule->new('Pkg')->mock(m => sub { ... })
Skip tests
SKIP: { skip 'reason', $count unless $cond; ... }
TODO tests
TODO: { local $TODO = 'reason'; ... }
Common Pitfalls
Forgetting done_testing
perl
# Bad: Test file runs but doesn't verify all tests executeduse Test2::V0;
is(1, 1, 'works');
# Missing done_testing — silent bugs if test code is skipped# Good: Always end with done_testinguse Test2::V0;
is(1, 1, 'works');
done_testing;
Missing -l Flag
bash
# Bad: Modules in lib/ not found
prove t/unit/user.t
# Can't locate MyApp/User.pm in @INC# Good: Include lib/ in @INC
prove -l t/unit/user.t
Over-Mocking
Mock the dependency, not the code under test. If your test only verifies that a mock returns what you told it to, it tests nothing.
Test Pollution
Use my variables inside subtests — never our — to prevent state leaking between tests.
Remember: Tests are your safety net. Keep them fast, focused, and independent. Use Test2::V0 for new projects, prove for running, and Devel::Cover for accountability.
Add this badge to a GitHub README so readers can open the package page and install the same version.
[](https://www.aipm-registry.com/skills/affaan-m/perl-testing/1.0.0?utm_source=github&utm_medium=readme&utm_campaign=package_badge)
This imported publisher has not claimed its AIPM account. A connected account confirms account control, but it does not guarantee that a package is safe.
AI assistant context
What this skill is for
@affaan-m/perl-testing@1.0.0 is an AIPM skill package for All tools. Use it when a project needs the reusable AI behavior described as: Perl testing patterns using Test2::V0, Test::More, prove runner, mocking, coverage with Devel::Cover, and TDD methodology. Use when writing Perl tests with Test2::V0 or Test::More, or measuring coverage.
Preview a UI component mockup in a local browser canvas where the human directly edits it (move, resize, edit text, delete, restyle), switches mobile/desktop/custom viewports, tests it, chats with you, and clicks Save and Finish. You the...
Run aipm add @affaan-m/perl-testing@1.0.0 in a project that has AIPM initialized.
Supported tools
@affaan-m/perl-testing@1.0.0 supports All tools.
Before installing
AIPM skills can add files to your project. Review the package name, target, description, license, and publisher before installing. Use a clean branch when trying a new skill.