Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: another benefit of one-liners

by Falkkin (Chaplain)
on Feb 02, 2001 at 20:16 UTC ( [id://56010]=note: print w/replies, xml ) Need Help??


in reply to another benefit of one-liners

Of course, if you really want to test your objects, I'd recommend Test::Unit...

package Foo; ## BEGIN UNIT TESTING use Test::Unit; print "Testing Foo: "; create_suite(); run_suite(); print "\n\n"; sub test_new { my $foo = Foo->new(name => 'Bar', baz => "Quux"); # Test to make sure it was constructed correctly. assert($foo->get_name() eq 'Bar'); assert($foo->get_baz() eq 'Quux'); # My constructor should die if called with no args, check for that w +ith this line: eval { my $foo = Foo->new() }; assert($@); } sub test_method_1 { my $foo = Foo->new(name => 'Bar', baz => 'foon'); assert($foo->gurglify(15)); assert($foo->gurgled_amount() == 15); }
... and so on. I typically use one single test for each method, along with a couple moe complicated tests that make sure the methods interact correctly. Run them all with perl Foo.pm every time you change anything within the file, and you can be assured that it all still works (as long as your tests are comprehensive...)

Replies are listed 'Best First'.
Re: Re: another benefit of one-liners
by Adam (Vicar) on Feb 02, 2001 at 23:04 UTC
    Unit Tests are definately a programmers friend. I wish I could give you more then one ++ for bringing this up. Lets just pretend that I gave you 2 ++ votes, and one vindictive -- vote for beating me to it. :-)

    Seriously though, the only thing better then a unit test which covers all the methods and exercises all the code including error cases.... is a Perl script to run all those tests for you! After I make changes to a chunk of code, I run my tests with a single script, which tells me where all my blatant bugs are. Very useful indeed. (And gives you that nice warm feeling when the test passes)

Re: Re: another benefit of one-liners
by geektron (Curate) on Feb 02, 2001 at 23:57 UTC
    quite true. i haven't used the Unit::Test - i end up rolling my own.

    i'll have to look into it. . . :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://56010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-18 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found