PE

Perl Testing Defaults

Perl testing conventions using Test::More and the TAP protocol

Details

Language / Topic
perlPerl
Category
Testing

Rules

balanced
- Use `Test::More` — start test files with `use Test::More tests => N;` or `use Test::More;` with `done_testing()` at the end.
- Use `ok()`, `is()`, `isnt()`, `like()`, and `cmp_ok()` for assertions — always provide a test name as the last argument.
- Place tests in `t/` and run them with `prove -lv t/` — use `prove -r` to recurse into subdirectories.
- Use `is_deeply()` to compare complex data structures (arrays, hashes) — it gives a structured diff on failure.
- Use `Test::Exception` (`throws_ok`, `lives_ok`) to assert that code throws or does not throw exceptions.
- Use `Test::Warn` to assert that specific warnings are or are not emitted during a block of code.
- Group related tests into subtests with `subtest 'description' => sub { ... }` to organize output and isolate failures.