Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: another benefit of one-liners

by Falkkin (Chaplain)
on Feb 02, 2001 at 20:16 UTC ( #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 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://56010]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-01-24 15:56 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (206 votes). Check out past polls.