How can I cover this try/catch portion?

2 views
Skip to first unread message

Kim Beom-soo

unread,
Dec 4, 2011, 6:07:11 PM12/4/11
to CPSC410-2011
I'm having trouble covering try/catch portion of my code dealing with
SQL Query.


// free DB objects
finally {
try {
if (rs != null)
rs.close();
<------------------------------------------------------------------------------------------
} catch (Exception e) {
System.out.println("Cannot close ResultSet: " + e.getMessage());
<--------------------------------------------------------
}
try {
if (pst != null)
pst.close();
<---------------------------------------------------------------------------------
} catch (Exception e) {
System.out.println("Cannot close PreparedStatement: "
<-------------------------------------------------------------------------------
+ e.getMessage());
<----------------------------------------------------------------------
}
dbManager.freeConnection(conn);
}
return false;

}

I don't know how to cover these arrowed parts.

I can I force ResultSet(rs) and Prepared Statement(pst) to make a
error and throw exception???

It turns about that, If I miss these 2 parts, I lose 40% of my
coverage!!!

Any ideas???


Beom-soo Kim

Eric Wohlstadter

unread,
Dec 4, 2011, 8:42:42 PM12/4/11
to cpsc41...@googlegroups.com
Yes, this is why you only need 80% coverage. You only need 80% coverage on average over all your code. So if you can't get 80% on this class, you should be able over-compensate somewhere else. 

Eric
Reply all
Reply to author
Forward
0 new messages