|
|
Choosing A Webhost: |
Re: Bad test functions in Test::Exception: msg#00228lang.perl.quality-assurance
Subject: Bad test functions in Test::Exception From: Nadim Khemir <nadim@xxxxxxxxxx> Date: Tue, 30 Jan 2007 18:17:38 +0100 }I like Test::Exception, it's a very fundamental test module with }Text::NoWarning, Test::Deep and other goodies. Still, I believe some of the }functions made available should not be there at all. Not everyone uses Perl the way you do. Different people have needs for different functions. Saying "I don't use this and can't think of a reason for it, so get rid of it" makes a lot of assumptions, many of which probably aren't true. } # Check that something died } dies_ok { $foo->method1 } 'expecting to die'; } }Am I the only one who got this to pass, to find out later that what cause the }error had nothing to do with the message I displayed. No, you're not - but shunning all possible uses of dies_ok becasue you didn't write a test as complete as you could have isn't the fault of Test::Exception. How about code that dies with an object? dies_ok lets you inspect the object in $@, whereas throws_ok only lets you see if it's part of a class. What if you want to see if $@ meets multiple criteria? There's plenty of valid cases where throws_ok just isn't enough. And finally, what if I truly don't care why something dies, just that it did? Why should I be penalized for writing *any* test? } # Check that something did not die } lives_ok { $foo->method2 } 'expecting to live'; } }Is the above realy a test? Ok but testing what? why wouldn't we wrap all our }test in lives_ok? No, I don't think lives_ok makes any sense. I'd be very }happy to see real examples of lives_ok that add anything to a test suite. I have this in the production code where I work, and it's very necessary. If you have an interface that requires you to die on invalid input, it's a life-saver, especially during debugging. While I won't paste code from my work here, consider your exact case: } # Check that a test runs without an exception } lives_and { is $foo->method, 42 } 'method is 42'; }Isn't this equivalent to is($foo->method, 42 , 'method is 42') ? No! If the latter fails, the test stops where it is, and no further tests proceed. If the former fails, it's another 'nok' to investigate, but the rest of your tests have an opportunity to run. }I postulate that Test::Exception would be even better if we removed the bad }guys. And I postulate that you're not willing to change all the code in the world that uses them, for reasons I've stated above and more. Besides which, if you remove those functions, people will either stop using the module (and possibly stop testing as much) or will invoke the laziness part of Perl and do this: throws_ok { $foo->method } qr//, 'method dies' People have personal and organizational code standards to meet, and that's to be expected. Be sure to update yours to the things you've mentioned. TIMTOWTDI rules here, though, and PBP isn't a rulebook - it's a set of guidelines that work for Damian. Other people use them to varying degrees, and P::C even implements them, but at some point, people are on their own. -Pete K -- Pete Krawczyk perl at bsod dot net
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Bad test functions in Test::Exception, Nadim Khemir |
|---|---|
| Next by Date: | Re: Bad test functions in Test::Exception, A. Pagaltzis |
| Previous by Thread: | Bad test functions in Test::Exception, Nadim Khemir |
| Next by Thread: | Re: Bad test functions in Test::Exception, A. Pagaltzis |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |