Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^5: Making open fail

by SilasTheMonk (Chaplain)
on Jul 05, 2010 at 14:50 UTC ( #848076=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Making open fail
in thread Making open fail

hmmm... I wonder if there is some confusion going on here. The way Devel::Cover measures test coverage is what percentage of the lines and branches in the code are executed by at least one test. If you tried it you would see how it works. Ideally private methods should not be tested directly - only indirectly - because they are private methods. That may not always be possible but it should be most of the time.


Comment on Re^5: Making open fail
Re^6: Making open fail
by bluescreen (Friar) on Jul 05, 2010 at 18:30 UTC

    I know Devel::Cover in fact we've it tied to Hudson continuous integration server to automatically generate coverage report for our app ( Hudson also does perldoc, load testing and profiling using Devel::NYTProf).

    The whole point is to avoid becoming obsessed about the 100% number, because it doesn't guarantees you anything. In fact most valuables test cases we have rarely increments the coverage % as they are border cases or special conditions of things that are already covered.

    I don't think you have to aim to have 100%, I think you have to aim to have a consistent test suite where critical paths are good covered.

    Ideally private methods are not tested directly, but what if you have the following code

    sub method_a { ... open(...) or die "First ..."; ... $self->_method_b(); } sub _method_b { ... open(...) or die "Second ..."; $self->_method_c(); } sub _method_c { ... open(...) or die "Third ..."; }

    Now you want to test an error condition in the third open so have mock of the open method and depending on the method's caller the open will return true or false, so your mock's code will have something like

    if ( $caller eq '_method_c') { return 0; } return 1; }

    Indirectly your test code becomes dependent of _method_c (private method), as a rule of thumb the more nested private method calls you have the more complex the test case will become, sometimes it makes sense to test the private method directly.

    There is a good article Give me 100% Code Coverage or Give Me Death!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2014-07-28 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (204 votes), past polls