What is the correct way to unit test areas around exceptions

Posted by Codek on Stack Overflow See other posts from Stack Overflow or by Codek
Published on 2010-05-20T11:23:16Z Indexed on 2010/05/20 11:30 UTC
Read the original article Hit count: 309

Hi,

Looking at our code coverage of our unit tests we're quite high. But the last few % is tricky because a lot of them are catching things like database exceptions - which in normal circumstances just dont happen. For example the code prevents fields being too long etc, so the only possible database exceptions are if the DB is broken/down, or if the schema is changed under our feet.

So is the only way to Mock the objects such that the exception can be thrown? That seems a little bit pointless. Perhaps it's better to just accept not getting 100% code coverage?

Thanks, Dan

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about exceptions