Meaningless Drivel is fun!*
The moose likes Testing and the fly likes How to handle code coverage for catch blocks? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to handle code coverage for catch blocks?" Watch "How to handle code coverage for catch blocks?" New topic
Author

How to handle code coverage for catch blocks?

Giriraj Bhojak
Ranch Hand

Joined: Apr 03, 2008
Posts: 71
I am trying to improve code coverage of our enterprise application.
Is there an approved way to handle catch blocks?
How do i increase code coverage by running tests that lets the control go to catch block?

I hope my query is clear enough.

Thanks,
Giriraj.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Giriraj,
What tool are you using for code coverage? Different tools handle catch blocks differently.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Giriraj Bhojak
Ranch Hand

Joined: Apr 03, 2008
Posts: 71
I am using Clover.
Testing each and every catch block is exhaustive and seems improbable to me.
But there has to be way to handle most of the error conditions.

Thanks,
Giriraj.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

One way is to have less catch blocks. Can a filter or superclass handle the common ones?
Giriraj Bhojak
Ranch Hand

Joined: Apr 03, 2008
Posts: 71
That would require refactoring which unfortunately isn't an option for me right now.
I simply have to improve the coverage for existing code base.
What else could you suggest?

Thanks a ton for replying...

Giriraj.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to handle code coverage for catch blocks?
 
Similar Threads
Simulating Exceptions?
Journal Article - Introduction to Code Coverage
Help wanted ! PLease explain what is try and catch use for .
Escaping the Exception Trap
Runtime Exceptions, Do they need try-catch at all?/