#15 Unit tests should use finally to close resources

open
nobody
junit (1)
1
2012-12-30
2012-11-06
John May
No

When a unit test opens a resource it should ensure it is always closed. This can be accomplished using a finally block without the catch. This way the exceptions are still thrown.

InputStream in = ...
try {
   // io logic
} finally {
   in.close()
}

Related

Junior Jobs: #15

Discussion

  • Sambit Gaan
    Sambit Gaan
    2012-12-30

    What I can understand is that this ticket talks about the closing of the resources where ever the resources are open. Is it still open, can I take up this task? And we have to do it on trunk I guess.

     
  • John May
    John May
    2012-12-30

    Yep it's still open. In many of the tests a stream is opened but never closed (bad) or it is opened and closed outside of a finally (not too bad).

    These will be spread all over the test suite but there may be a concentration in the io module.

    Also, the svn (and thus trunk) is only there for legacy - I believe they're quite far behind now. I would put these changes on the 'master' branch of the git repo. The current stable is 'cdk-1.4.x' but these changes only affect development and so there is no gain in putting it on stable.

    Sent from my iPhone

    On 30 Dec 2012, at 11:31, "Sambit Gaan" sambitgaan@users.sf.net wrote:

    What I can understand is that this ticket talks about the closing of the resources where ever the resources are open. Is it still open, can I take up this task? And we have to do it on trunk I guess.

    [junior-jobs:#15] Unit tests should use finally to close resources

    Status: open
    Labels: junit
    Created: Tue Nov 06, 2012 10:39 AM UTC by John May
    Last Updated: Tue Nov 06, 2012 10:39 AM UTC
    Owner: nobody

    When a unit test opens a resource it should ensure it is always closed. This can be accomplished using a finally block without the catch. This way the exceptions are still thrown.

    InputStream in = ...
    try {
    // io logic
    } finally {
    in.close()
    }
    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/cdk/junior-jobs/15/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/prefs/

     

    Related

    Junior Jobs: #15