Ignoring code in catch blocks

308 views
Skip to first unread message

Ran Cohen

unread,
Nov 13, 2017, 8:30:51 AM11/13/17
to JaCoCo and EclEmma Users
I have general catch blocks, that attached to exceptions almost impossibly thrown.
Because its almost impossible to cause an exception, and also because they just re-throw the exception, I don't test them, but Jacoco marks the catch block as not tested, which is ugly...
How can I tell Jacoco to ignore this blocks (or any other code for that matter)?

Marc Hoffmann

unread,
Nov 14, 2017, 1:35:55 AM11/14/17
to jac...@googlegroups.com

Hi Ran,

JaCoCo does not have an option to exclude parts of a method. We have an open feature request for this:

https://github.com/jacoco/jacoco/issues/14

For a couple of reasons it is very unlikely that such functionality will be added to JaCoCo soon.

Regards,
-marc

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/0343570e-0e32-4004-b2b3-55afedd4c280%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Ran Cohen

unread,
Nov 14, 2017, 1:41:03 AM11/14/17
to JaCoCo and EclEmma Users
In the mean time - what can I do? How can I test catch-blocks that would rarely occur (and are almost impossible to replicate)?  

Marc Hoffmann

unread,
Nov 14, 2017, 1:54:24 AM11/14/17
to jac...@googlegroups.com

There are different strategies:

  • Use mocking to test those exceptions (assuming you have a proper delegate which can be mocked)
  • Change your exception hierarchies or method signatures to avoid such catch blocks
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages