[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F0KBZPY2VENJN72G92G8S0":3,"skill-same:01M7F0KBZPY2VENJN72G92G8S0":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":14,"repositoryHtmlUrl":29,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M7F0KBZPY2VENJN72G92G8S0","perl-testing",null,"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.","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fecc\u002Fperl-testing\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: perl-testing\ndescription: 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.\nmetadata:\n  origin: ECC\n---\n\n# Perl Testing Patterns\n\nComprehensive testing strategies for Perl applications using Test2::V0, Test::More, prove, and TDD methodology.\n\n## When to Activate\n\n- Writing new Perl code (follow TDD: red, green, refactor)\n- Designing test suites for Perl modules or applications\n- Reviewing Perl test coverage\n- Setting up Perl testing infrastructure\n- Migrating tests from Test::More to Test2::V0\n- Debugging failing Perl tests\n\n## TDD Workflow\n\nAlways follow the RED-GREEN-REFACTOR cycle.\n\n```perl\n# Step 1: RED — Write a failing test\n# t\u002Funit\u002Fcalculator.t\nuse v5.36;\nuse Test2::V0;\n\nuse lib 'lib';\nuse Calculator;\n\nsubtest 'addition' => sub {\n    my $calc = Calculator->new;\n    is($calc->add(2, 3), 5, 'adds two numbers');\n    is($calc->add(-1, 1), 0, 'handles negatives');\n};\n\ndone_testing;\n\n# Step 2: GREEN — Write minimal implementation\n# lib\u002FCalculator.pm\npackage Calculator;\nuse v5.36;\nuse Moo;\n\nsub add($self, $a, $b) {\n    return $a + $b;\n}\n\n1;\n\n# Step 3: REFACTOR — Improve while tests stay green\n# Run: prove -lv t\u002Funit\u002Fcalculator.t\n```\n\n## Test::More Fundamentals\n\nThe standard Perl testing module — widely used, ships with core.\n\n### Basic Assertions\n\n```perl\nuse v5.36;\nuse Test::More;\n\n# Plan upfront or use done_testing\n# plan tests => 5;  # Fixed plan (optional)\n\n# Equality\nis($result, 42, 'returns correct value');\nisnt($result, 0, 'not zero');\n\n# Boolean\nok($user->is_active, 'user is active');\nok(!$user->is_banned, 'user is not banned');\n\n# Deep comparison\nis_deeply(\n    $got,\n    { name => 'Alice', roles => ['admin'] },\n    'returns expected structure'\n);\n\n# Pattern matching\nlike($error, qr\u002Fnot found\u002Fi, 'error mentions not found');\nunlike($output, qr\u002Fpassword\u002F, 'output hides password');\n\n# Type check\nisa_ok($obj, 'MyApp::User');\ncan_ok($obj, 'save', 'delete');\n\ndone_testing;\n```\n\n### SKIP and TODO\n\n```perl\nuse v5.36;\nuse Test::More;\n\n# Skip tests conditionally\nSKIP: {\n    skip 'No database configured', 2 unless $ENV{TEST_DB};\n\n    my $db = connect_db();\n    ok($db->ping, 'database is reachable');\n    is($db->version, '15', 'correct PostgreSQL version');\n}\n\n# Mark expected failures\nTODO: {\n    local $TODO = 'Caching not yet implemented';\n    is($cache->get('key'), 'value', 'cache returns value');\n}\n\ndone_testing;\n```\n\n## Test2::V0 Modern Framework\n\nTest2::V0 is the modern replacement for Test::More — richer assertions, better diagnostics, and extensible.\n\n### Why Test2?\n\n- Superior deep comparison with hash\u002Farray builders\n- Better diagnostic output on failures\n- Subtests with cleaner scoping\n- Extensible via Test2::Tools::* plugins\n- Backward-compatible with Test::More tests\n\n### Deep Comparison with Builders\n\n```perl\nuse v5.36;\nuse Test2::V0;\n\n# Hash builder — check partial structure\nis(\n    $user->to_hash,\n    hash {\n        field name  => 'Alice';\n        field email => match(qr\u002F\\@example\\.com$\u002F);\n        field age   => validator(sub { $_ >= 18 });\n        # Ignore other fields\n        etc();\n    },\n    'user has expected fields'\n);\n\n# Array builder\nis(\n    $result,\n    array {\n        item 'first';\n        item match(qr\u002F^second\u002F);\n        item DNE();  # Does Not Exist — verify no extra items\n    },\n    'result matches expected list'\n);\n\n# Bag — order-independent comparison\nis(\n    $tags,\n    bag {\n        item 'perl';\n        item 'testing';\n        item 'tdd';\n    },\n    'has all required tags regardless of order'\n);\n```\n\n### Subtests\n\n```perl\nuse v5.36;\nuse Test2::V0;\n\nsubtest 'User creation' => sub {\n    my $user = User->new(name => 'Alice', email => 'alice@example.com');\n    ok($user, 'user object created');\n    is($user->name, 'Alice', 'name is set');\n    is($user->email, 'alice@example.com', 'email is set');\n};\n\nsubtest 'User validation' => sub {\n    my $warnings = warns {\n        User->new(name => '', email => 'bad');\n    };\n    ok($warnings, 'warns on invalid data');\n};\n\ndone_testing;\n```\n\n### Exception Testing with Test2\n\n```perl\nuse v5.36;\nuse Test2::V0;\n\n# Test that code dies\nlike(\n    dies { divide(10, 0) },\n    qr\u002FDivision by zero\u002F,\n    'dies on division by zero'\n);\n\n# Test that code lives\nok(lives { divide(10, 2) }, 'division succeeds') or note($@);\n\n# Combined pattern\nsubtest 'error handling' => sub {\n    ok(lives { parse_config('valid.json') }, 'valid config parses');\n    like(\n        dies { parse_config('missing.json') },\n        qr\u002FCannot open\u002F,\n        'missing file dies with message'\n    );\n};\n\ndone_testing;\n```\n\n## Test Organization and prove\n\n### Directory Structure\n\n```text\nt\u002F\n├── 00-load.t              # Verify modules compile\n├── 01-basic.t             # Core functionality\n├── unit\u002F\n│   ├── config.t           # Unit tests by module\n│   ├── user.t\n│   └── util.t\n├── integration\u002F\n│   ├── database.t\n│   └── api.t\n├── lib\u002F\n│   └── TestHelper.pm      # Shared test utilities\n└── fixtures\u002F\n    ├── config.json        # Test data files\n    └── users.csv\n```\n\n### prove Commands\n\n```bash\n# Run all tests\nprove -l t\u002F\n\n# Verbose output\nprove -lv t\u002F\n\n# Run specific test\nprove -lv t\u002Funit\u002Fuser.t\n\n# Recursive search\nprove -lr t\u002F\n\n# Parallel execution (8 jobs)\nprove -lr -j8 t\u002F\n\n# Run only failing tests from last run\nprove -l --state=failed t\u002F\n\n# Colored output with timer\nprove -l --color --timer t\u002F\n\n# TAP output for CI\nprove -l --formatter TAP::Formatter::JUnit t\u002F > results.xml\n```\n\n### .proverc Configuration\n\n```text\n-l\n--color\n--timer\n-r\n-j4\n--state=save\n```\n\n## Fixtures and Setup\u002FTeardown\n\n### Subtest Isolation\n\n```perl\nuse v5.36;\nuse Test2::V0;\nuse File::Temp qw(tempdir);\nuse Path::Tiny;\n\nsubtest 'file processing' => sub {\n    # Setup\n    my $dir = tempdir(CLEANUP => 1);\n    my $file = path($dir, 'input.txt');\n    $file->spew_utf8(\"line1\\nline2\\nline3\\n\");\n\n    # Test\n    my $result = process_file(\"$file\");\n    is($result->{line_count}, 3, 'counts lines');\n\n    # Teardown happens automatically (CLEANUP => 1)\n};\n```\n\n### Shared Test Helpers\n\nPlace reusable helpers in `t\u002Flib\u002FTestHelper.pm` and load with `use lib 't\u002Flib'`. Export factory functions like `create_test_db()`, `create_temp_dir()`, and `fixture_path()` via `Exporter`.\n\n## Mocking\n\n### Test::MockModule\n\n```perl\nuse v5.36;\nuse Test2::V0;\nuse Test::MockModule;\n\nsubtest 'mock external API' => sub {\n    my $mock = Test::MockModule->new('MyApp::API');\n\n    # Good: Mock returns controlled data\n    $mock->mock(fetch_user => sub ($self, $id) {\n        return { id => $id, name => 'Mock User', email => 'mock@test.com' };\n    });\n\n    my $api = MyApp::API->new;\n    my $user = $api->fetch_user(42);\n    is($user->{name}, 'Mock User', 'returns mocked user');\n\n    # Verify call count\n    my $call_count = 0;\n    $mock->mock(fetch_user => sub { $call_count++; return {} });\n    $api->fetch_user(1);\n    $api->fetch_user(2);\n    is($call_count, 2, 'fetch_user called twice');\n\n    # Mock is automatically restored when $mock goes out of scope\n};\n\n# Bad: Monkey-patching without restoration\n# *MyApp::API::fetch_user = sub { ... };  # NEVER — leaks across tests\n```\n\nFor lightweight mock objects, use `Test::MockObject` to create injectable test doubles with `->mock()` and verify calls with `->called_ok()`.\n\n## Coverage with Devel::Cover\n\n### Running Coverage\n\n```bash\n# Basic coverage report\ncover -test\n\n# Or step by step\nperl -MDevel::Cover -Ilib t\u002Funit\u002Fuser.t\ncover\n\n# HTML report\ncover -report html\nopen cover_db\u002Fcoverage.html\n\n# Specific thresholds\ncover -test -report text | grep 'Total'\n\n# CI-friendly: fail under threshold\ncover -test && cover -report text -select '^lib\u002F' \\\n  | perl -ne 'if (\u002FTotal.*?(\\d+\\.\\d+)\u002F) { exit 1 if $1 \u003C 80 }'\n```\n\n### Integration Testing\n\nUse in-memory SQLite for database tests, mock HTTP::Tiny for API tests.\n\n```perl\nuse v5.36;\nuse Test2::V0;\nuse DBI;\n\nsubtest 'database integration' => sub {\n    my $dbh = DBI->connect('dbi:SQLite:dbname=:memory:', '', '', {\n        RaiseError => 1,\n    });\n    $dbh->do('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');\n\n    $dbh->prepare('INSERT INTO users (name) VALUES (?)')->execute('Alice');\n    my $row = $dbh->selectrow_hashref('SELECT * FROM users WHERE name = ?', undef, 'Alice');\n    is($row->{name}, 'Alice', 'inserted and retrieved user');\n};\n\ndone_testing;\n```\n\n## Best Practices\n\n### DO\n\n- **Follow TDD**: Write tests before implementation (red-green-refactor)\n- **Use Test2::V0**: Modern assertions, better diagnostics\n- **Use subtests**: Group related assertions, isolate state\n- **Mock external dependencies**: Network, database, file system\n- **Use `prove -l`**: Always include lib\u002F in `@INC`\n- **Name tests clearly**: `'user login with invalid password fails'`\n- **Test edge cases**: Empty strings, undef, zero, boundary values\n- **Aim for 80%+ coverage**: Focus on business logic paths\n- **Keep tests fast**: Mock I\u002FO, use in-memory databases\n\n### DON'T\n\n- **Don't test implementation**: Test behavior and output, not internals\n- **Don't share state between subtests**: Each subtest should be independent\n- **Don't skip `done_testing`**: Ensures all planned tests ran\n- **Don't over-mock**: Mock boundaries only, not the code under test\n- **Don't use `Test::More` for new projects**: Prefer Test2::V0\n- **Don't ignore test failures**: All tests must pass before merge\n- **Don't test CPAN modules**: Trust libraries to work correctly\n- **Don't write brittle tests**: Avoid over-specific string matching\n\n## Quick Reference\n\n| Task | Command \u002F Pattern |\n|---|---|\n| Run all tests | `prove -lr t\u002F` |\n| Run one test verbose | `prove -lv t\u002Funit\u002Fuser.t` |\n| Parallel test run | `prove -lr -j8 t\u002F` |\n| Coverage report | `cover -test && cover -report html` |\n| Test equality | `is($got, $expected, 'label')` |\n| Deep comparison | `is($got, hash { field k => 'v'; etc() }, 'label')` |\n| Test exception | `like(dies { ... }, qr\u002Fmsg\u002F, 'label')` |\n| Test no exception | `ok(lives { ... }, 'label')` |\n| Mock a method | `Test::MockModule->new('Pkg')->mock(m => sub { ... })` |\n| Skip tests | `SKIP: { skip 'reason', $count unless $cond; ... }` |\n| TODO tests | `TODO: { local $TODO = 'reason'; ... }` |\n\n## Common Pitfalls\n\n### Forgetting `done_testing`\n\n```perl\n# Bad: Test file runs but doesn't verify all tests executed\nuse Test2::V0;\nis(1, 1, 'works');\n# Missing done_testing — silent bugs if test code is skipped\n\n# Good: Always end with done_testing\nuse Test2::V0;\nis(1, 1, 'works');\ndone_testing;\n```\n\n### Missing `-l` Flag\n\n```bash\n# Bad: Modules in lib\u002F not found\nprove t\u002Funit\u002Fuser.t\n# Can't locate MyApp\u002FUser.pm in @INC\n\n# Good: Include lib\u002F in @INC\nprove -l t\u002Funit\u002Fuser.t\n```\n\n### Over-Mocking\n\nMock the *dependency*, not the code under test. If your test only verifies that a mock returns what you told it to, it tests nothing.\n\n### Test Pollution\n\nUse `my` variables inside subtests — never `our` — to prevent state leaking between tests.\n\n**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.\n","# Perl Testing Patterns\n\nComprehensive testing strategies for Perl applications using Test2::V0, Test::More, prove, and TDD methodology.\n\n## When to Activate\n\n- Writing new Perl code (follow TDD: red, green, refactor)\n- Designing test suites for Perl modules or applications\n- Reviewing Perl test coverage\n- Setting up Perl testing infrastructure\n- Migrating tests from Test::More to Test2::V0\n- Debugging failing Perl tests\n\n## TDD Workflow\n\nAlways follow the RED-GREEN-REFACTOR cycle.\n\n```perl\n# Step 1: RED — Write a failing test\n# t\u002Funit\u002Fcalculator.t\nuse v5.36;\nuse Test2::V0;\n\nuse lib 'lib';\nuse Calculator;\n\nsubtest 'addition' => sub {\n    my $calc = Calculator->new;\n    is($calc->add(2, 3), 5, 'adds two numbers');\n    is($calc->add(-1, 1), 0, 'handles negatives');\n};\n\ndone_testing;\n\n# Step 2: GREEN — Write minimal implementation\n# lib\u002FCalculator.pm\npackage Calculator;\nuse v5.36;\nuse Moo;\n\nsub add($self, $a, $b) {\n    return $a + $b;\n}\n\n1;\n\n# Step 3: REFACTOR — Improve while tests stay green\n# Run: prove -lv t\u002Funit\u002Fcalculator.t\n```\n\n## Test::More Fundamentals\n\nThe standard Perl testing module — widely used, ships with core.\n\n### Basic Assertions\n\n```perl\nuse v5.36;\nuse Test::More;\n\n# Plan upfront or use done_testing\n# plan tests => 5;  # Fixed plan (optional)\n\n# Equality\nis($result, 42, 'returns correct value');\nisnt($result, 0, 'not zero');\n\n# Boolean\nok($user->is_active, 'user is active');\nok(!$user->is_banned, 'user is not banned');\n\n# Deep comparison\nis_deeply(\n    $got,\n    { name => 'Alice', roles => ['admin'] },\n    'returns expected structure'\n);\n\n# Pattern matching\nlike($error, qr\u002Fnot found\u002Fi, 'error mentions not found');\nunlike($output, qr\u002Fpassword\u002F, 'output hides password');\n\n# Type check\nisa_ok($obj, 'MyApp::User');\ncan_ok($obj, 'save', 'delete');\n\ndone_testing;\n```\n\n### SKIP and TODO\n\n```perl\nuse v5.36;\nuse Test::More;\n\n# Skip tests conditionally\nSKIP: {\n    skip 'No database configured', 2 unless $ENV{TEST_DB};\n\n    my $db = connect_db();\n    ok($db->ping, 'database is reachable');\n    is($db->version, '15', 'correct PostgreSQL version');\n}\n\n# Mark expected failures\nTODO: {\n    local $TODO = 'Caching not yet implemented';\n    is($cache->get('key'), 'value', 'cache returns value');\n}\n\ndone_testing;\n```\n\n## Test2::V0 Modern Framework\n\nTest2::V0 is the modern replacement for Test::More — richer assertions, better diagnostics, and extensible.\n\n### Why Test2?\n\n- Superior deep comparison with hash\u002Farray builders\n- Better diagnostic output on failures\n- Subtests with cleaner scoping\n- Extensible via Test2::Tools::* plugins\n- Backward-compatible with Test::More tests\n\n### Deep Comparison with Builders\n\n```perl\nuse v5.36;\nuse Test2::V0;\n\n# Hash builder — check partial structure\nis(\n    $user->to_hash,\n    hash {\n        field name  => 'Alice';\n        field email => match(qr\u002F\\@example\\.com$\u002F);\n        field age   => validator(sub { $_ >= 18 });\n        # Ignore other fields\n        etc();\n    },\n    'user has expected fields'\n);\n\n# Array builder\nis(\n    $result,\n    array {\n        item 'first';\n        item match(qr\u002F^second\u002F);\n        item DNE();  # Does Not Exist — verify no extra items\n    },\n    'result matches expected list'\n);\n\n# Bag — order-independent comparison\nis(\n    $tags,\n    bag {\n        item 'perl';\n        item 'testing';\n        item 'tdd';\n    },\n    'has all required tags regardless of order'\n);\n```\n\n### Subtests\n\n```perl\nuse v5.36;\nuse Test2::V0;\n\nsubtest 'User creation' => sub {\n    my $user = User->new(name => 'Alice', email => 'alice@example.com');\n    ok($user, 'user object created');\n    is($user->name, 'Alice', 'name is set');\n    is($user->email, 'alice@example.com', 'email is set');\n};\n\nsubtest 'User validation' => sub {\n    my $warnings = warns {\n        User->new(name => '', email => 'bad');\n    };\n    ok($warnings, 'warns on invalid data');\n};\n\ndone_testing;\n```\n\n### Exception Testing with Test2\n\n```perl\nuse v5.36;\nuse Test2::V0;\n\n# Test that code dies\nlike(\n    dies { divide(10, 0) },\n    qr\u002FDivision by zero\u002F,\n    'dies on division by zero'\n);\n\n# Test that code lives\nok(lives { divide(10, 2) }, 'division succeeds') or note($@);\n\n# Combined pattern\nsubtest 'error handling' => sub {\n    ok(lives { parse_config('valid.json') }, 'valid config parses');\n    like(\n        dies { parse_config('missing.json') },\n        qr\u002FCannot open\u002F,\n        'missing file dies with message'\n    );\n};\n\ndone_testing;\n```\n\n## Test Organization and prove\n\n### Directory Structure\n\n```text\nt\u002F\n├── 00-load.t              # Verify modules compile\n├── 01-basic.t             # Core functionality\n├── unit\u002F\n│   ├── config.t           # Unit tests by module\n│   ├── user.t\n│   └── util.t\n├── integration\u002F\n│   ├── database.t\n│   └── api.t\n├── lib\u002F\n│   └── TestHelper.pm      # Shared test utilities\n└── fixtures\u002F\n    ├── config.json        # Test data files\n    └── users.csv\n```\n\n### prove Commands\n\n```bash\n# Run all tests\nprove -l t\u002F\n\n# Verbose output\nprove -lv t\u002F\n\n# Run specific test\nprove -lv t\u002Funit\u002Fuser.t\n\n# Recursive search\nprove -lr t\u002F\n\n# Parallel execution (8 jobs)\nprove -lr -j8 t\u002F\n\n# Run only failing tests from last run\nprove -l --state=failed t\u002F\n\n# Colored output with timer\nprove -l --color --timer t\u002F\n\n# TAP output for CI\nprove -l --formatter TAP::Formatter::JUnit t\u002F > results.xml\n```\n\n### .proverc Configuration\n\n```text\n-l\n--color\n--timer\n-r\n-j4\n--state=save\n```\n\n## Fixtures and Setup\u002FTeardown\n\n### Subtest Isolation\n\n```perl\nuse v5.36;\nuse Test2::V0;\nuse File::Temp qw(tempdir);\nuse Path::Tiny;\n\nsubtest 'file processing' => sub {\n    # Setup\n    my $dir = tempdir(CLEANUP => 1);\n    my $file = path($dir, 'input.txt');\n    $file->spew_utf8(\"line1\\nline2\\nline3\\n\");\n\n    # Test\n    my $result = process_file(\"$file\");\n    is($result->{line_count}, 3, 'counts lines');\n\n    # Teardown happens automatically (CLEANUP => 1)\n};\n```\n\n### Shared Test Helpers\n\nPlace reusable helpers in `t\u002Flib\u002FTestHelper.pm` and load with `use lib 't\u002Flib'`. Export factory functions like `create_test_db()`, `create_temp_dir()`, and `fixture_path()` via `Exporter`.\n\n## Mocking\n\n### Test::MockModule\n\n```perl\nuse v5.36;\nuse Test2::V0;\nuse Test::MockModule;\n\nsubtest 'mock external API' => sub {\n    my $mock = Test::MockModule->new('MyApp::API');\n\n    # Good: Mock returns controlled data\n    $mock->mock(fetch_user => sub ($self, $id) {\n        return { id => $id, name => 'Mock User', email => 'mock@test.com' };\n    });\n\n    my $api = MyApp::API->new;\n    my $user = $api->fetch_user(42);\n    is($user->{name}, 'Mock User', 'returns mocked user');\n\n    # Verify call count\n    my $call_count = 0;\n    $mock->mock(fetch_user => sub { $call_count++; return {} });\n    $api->fetch_user(1);\n    $api->fetch_user(2);\n    is($call_count, 2, 'fetch_user called twice');\n\n    # Mock is automatically restored when $mock goes out of scope\n};\n\n# Bad: Monkey-patching without restoration\n# *MyApp::API::fetch_user = sub { ... };  # NEVER — leaks across tests\n```\n\nFor lightweight mock objects, use `Test::MockObject` to create injectable test doubles with `->mock()` and verify calls with `->called_ok()`.\n\n## Coverage with Devel::Cover\n\n### Running Coverage\n\n```bash\n# Basic coverage report\ncover -test\n\n# Or step by step\nperl -MDevel::Cover -Ilib t\u002Funit\u002Fuser.t\ncover\n\n# HTML report\ncover -report html\nopen cover_db\u002Fcoverage.html\n\n# Specific thresholds\ncover -test -report text | grep 'Total'\n\n# CI-friendly: fail under threshold\ncover -test && cover -report text -select '^lib\u002F' \\\n  | perl -ne 'if (\u002FTotal.*?(\\d+\\.\\d+)\u002F) { exit 1 if $1 \u003C 80 }'\n```\n\n### Integration Testing\n\nUse in-memory SQLite for database tests, mock HTTP::Tiny for API tests.\n\n```perl\nuse v5.36;\nuse Test2::V0;\nuse DBI;\n\nsubtest 'database integration' => sub {\n    my $dbh = DBI->connect('dbi:SQLite:dbname=:memory:', '', '', {\n        RaiseError => 1,\n    });\n    $dbh->do('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');\n\n    $dbh->prepare('INSERT INTO users (name) VALUES (?)')->execute('Alice');\n    my $row = $dbh->selectrow_hashref('SELECT * FROM users WHERE name = ?', undef, 'Alice');\n    is($row->{name}, 'Alice', 'inserted and retrieved user');\n};\n\ndone_testing;\n```\n\n## Best Practices\n\n### DO\n\n- **Follow TDD**: Write tests before implementation (red-green-refactor)\n- **Use Test2::V0**: Modern assertions, better diagnostics\n- **Use subtests**: Group related assertions, isolate state\n- **Mock external dependencies**: Network, database, file system\n- **Use `prove -l`**: Always include lib\u002F in `@INC`\n- **Name tests clearly**: `'user login with invalid password fails'`\n- **Test edge cases**: Empty strings, undef, zero, boundary values\n- **Aim for 80%+ coverage**: Focus on business logic paths\n- **Keep tests fast**: Mock I\u002FO, use in-memory databases\n\n### DON'T\n\n- **Don't test implementation**: Test behavior and output, not internals\n- **Don't share state between subtests**: Each subtest should be independent\n- **Don't skip `done_testing`**: Ensures all planned tests ran\n- **Don't over-mock**: Mock boundaries only, not the code under test\n- **Don't use `Test::More` for new projects**: Prefer Test2::V0\n- **Don't ignore test failures**: All tests must pass before merge\n- **Don't test CPAN modules**: Trust libraries to work correctly\n- **Don't write brittle tests**: Avoid over-specific string matching\n\n## Quick Reference\n\n| Task | Command \u002F Pattern |\n|---|---|\n| Run all tests | `prove -lr t\u002F` |\n| Run one test verbose | `prove -lv t\u002Funit\u002Fuser.t` |\n| Parallel test run | `prove -lr -j8 t\u002F` |\n| Coverage report | `cover -test && cover -report html` |\n| Test equality | `is($got, $expected, 'label')` |\n| Deep comparison | `is($got, hash { field k => 'v'; etc() }, 'label')` |\n| Test exception | `like(dies { ... }, qr\u002Fmsg\u002F, 'label')` |\n| Test no exception | `ok(lives { ... }, 'label')` |\n| Mock a method | `Test::MockModule->new('Pkg')->mock(m => sub { ... })` |\n| Skip tests | `SKIP: { skip 'reason', $count unless $cond; ... }` |\n| TODO tests | `TODO: { local $TODO = 'reason'; ... }` |\n\n## Common Pitfalls\n\n### Forgetting `done_testing`\n\n```perl\n# Bad: Test file runs but doesn't verify all tests executed\nuse Test2::V0;\nis(1, 1, 'works');\n# Missing done_testing — silent bugs if test code is skipped\n\n# Good: Always end with done_testing\nuse Test2::V0;\nis(1, 1, 'works');\ndone_testing;\n```\n\n### Missing `-l` Flag\n\n```bash\n# Bad: Modules in lib\u002F not found\nprove t\u002Funit\u002Fuser.t\n# Can't locate MyApp\u002FUser.pm in @INC\n\n# Good: Include lib\u002F in @INC\nprove -l t\u002Funit\u002Fuser.t\n```\n\n### Over-Mocking\n\nMock the *dependency*, not the code under test. If your test only verifies that a mock returns what you told it to, it tests nothing.\n\n### Test Pollution\n\nUse `my` variables inside subtests — never `our` — to prevent state leaking between tests.\n\n**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.\n",{"name":5,"metadata":24,"description":7},{"origin":25},"ECC","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Fecc\u002Fperl-testing","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill perl-testing",{"tool":38,"command":39},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill perl-testing",{"tool":41,"command":42},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill perl-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fecc\u002Fperl-testing\u002FSKILL.md",true,[],[47,54,61,68,75,82],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]