in reply to why Test::More?

The cases you provide are (admittedly) simplistic. When this becomes useful is when you have a method or function, and you want to document what its behavior should be

sub frobnitz { ... } ok( frobnitz( ) eq $no_params_results ); ok( frobnitz( @some_parameters ) eq $expected_results ); ok( frobnitz( @some_other_parameters) eq $other_expected_results );

The comparison can be any type of result that can be tested (does it throw / die, does it set some attribute on an object, etc).

The benefit of this is that you can quickly and consistently check the same behaviors, the same way, every time, after every change, to verify that you have not broken some expected behavior. This is a huge safety net when adding a feature, refactoring, etc. Your tests are, in effect, documentation, in the form of code, that translates English requirements into something that is less prone to misinterpretation more formalized.

--MidLifeXis

Replies are listed 'Best First'.
Re^2: why Test::More?
by Anonymous Monk on Sep 10, 2013 at 13:58 UTC
    thanks....opened my eyes. would you normally have a *.t file for every subroutine? How do you chain tests? (e.g. run t01.t .. t50.t)

      App::Prove is a typical harness that is used. Also see make test and build test in the build tool chain.

      I have been using (or trying to change my habits to use) Test Driven Development, to minimize the amount of untested code in my codebase. I have been using one .t file per package (well, per .pm file).*

      * - In reality, I use Test::Class with a unittests.t loader, but that is more of an implementation detail. In effect it is one test file per source file. Test::Class uses inheritance, but I think that test files could also be written using roles.

      --MidLifeXis

        App::ForkProve is nice as a more-or-less drop-in replacement for App::Prove.

        use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
        thank you