What does this skill do?

Testing in Perl with TDD Skill provides a structured framework for writing, running, and maintaining tests in Perl following the Red-Green-Refactor cycle. It uses modern frameworks such as Test2::V0 for in-depth comparisons and advanced diagnostics, integrates mocking with Test::MockModule to isolate external dependencies, and measures code coverage with Devel::Cover to ensure the quality of your Perl modules.

TDD Development
First, write the test that fails (Red), implement the minimum amount of code (Green), and refactor while keeping it green.
Migration to Test2::V0
Migrate legacy tests from Test::More to Test2::V0 to take advantage of better diagnostics and deep comparisons.
Dependency Mocking
Simulate external APIs, databases, and file systems using Test::MockModule to isolate the business logic.
Coverage Audit
Generate navigable HTML reports using Devel::Cover and verify that critical logic has at least 80% coverage.

Usage examples

🧪 Basic TDD Cycle
Write a test using Test2::V0 for a Calculator module that adds two numbers, following the Red-Green-Refactor cycle.
🔍 In-Depth Comparison
Create a test that verifies the structure of a user hash using the Test2::V0 builders with `match` and so on.
🧩 External API mock
Mock the `fetch_user` method of `MyApp::API` using `Test::MockModule` so that it returns a mock user.
📊 Coverage Report
Run the code coverage analysis using Devel::Cover and generate an HTML report for my Perl project.

Features

Structured TDD Cycle A step-by-step guide to the Red-Green-Refactor workflow adapted for modern Perl projects.
Test2::V0 and Test::More It supports the modern Test2::V0 framework with deep comparisons and maintains compatibility with the legacy Test::More.
Mocking with Test::MockModule It automatically isolates external components by simulating APIs, databases, and file systems.
Code Coverage with Devel::Cover Generate navigable HTML reports of executed lines, branches, and paths to audit code quality.
Test Organization Organize the tests in the t/ directory, with subfolders named unit/ and integration/, and shared utilities in t/lib/.

Frequently asked questions

Yes. To take full advantage of all its features, you'll need Test2::V0, Test::MockModule, and Devel::Cover. Install them using cpanm or your usual module manager.
Yes. The skill includes guidance on migrating tests from Test::More to Test2::V0 while maintaining compatibility with legacy projects.
Use the command `prove -l t/` to run the tests, making sure the `lib/` directory is in `@INC`. The TAP output will show the result of each test.
The skill recommends achieving over 80% coverage in the business logic. You can generate the report using `cover -report html` and view it in the cover_db/ directory.
Testing in Perl with TDD — Testing and Code Coverage with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.