I am using cobertura first time. Everything works fine but what I wonder is,
there are lines in my code, which should never be called like:
try {
em.persist();
}catch(Exception) {
logger.error("can not create");
}
I am doing all controls until persist line, when my code works fine, error line never be reached and now it is so. Because of it I never have %100 line coverage.
Should I somehow suppress it?
Thanks, Bilal
While you can exclude entire classes from your Cobertura coverage reports, you cannot exclude specific lines or methods.
You should accept that 100% coverage is impossible to achieve in real-life projects, since there will always be unreachable code or code that can only be reached by simulating a complex combination of conditions.
As other answers suggest, you can try and increase the unit test coverage by mocking/stubbing an
EntityManagerto throw an exception onpersist. But this is pretty much as far as you can go.