tag:blogger.com,1999:blog-19819012.post5000562567924987489..comments2023-06-28T20:26:42.987+05:30Comments on Random Thots: Unit Testing GuidelinesKaushikhttp://www.blogger.com/profile/01004068795704658410noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-19819012.post-37267599616527849632008-07-28T09:46:00.000+05:302008-07-28T09:46:00.000+05:30... Now I've long stopped doing unit-test *on* cat...... Now I've long stopped doing unit-test *on* catch-block ...<BR/><BR/>Something wrong with my englishHendry Lukhttps://www.blogger.com/profile/16180027255687806862noreply@blogger.comtag:blogger.com,1999:blog-19819012.post-44778234338948374942008-07-28T09:42:00.000+05:302008-07-28T09:42:00.000+05:30Regarding testing all possible flows, IMHO Java la...Regarding testing all possible flows, IMHO Java language design has biggest flaw in this. Especially checked-exception *feature*.<BR/><BR/>E.g. you have interface method that throws ExceptionA, ExceptionB, ExceptionC.<BR/>First... if your implementation contains block that throws other type of exception, you will need to add catch block that does nothing but to wrap it with either ExceptionA, B, or C. I used to write all unit-test to cover these block, but it gets old pretty quickly and feels pretty lame.<BR/>Secondly... suppose you want to intercept the exception before rethrow it (without AOP). Instead of having single Throwable catch block that rethrows the e, combined with the first issue, you will need to have 4 of them: 1 for each ExceptionA, B, C, plus another 1 to intercept and wrap Throwable. And it directly translates to 4 extra test-cases that offers no benefit but to reach that 3% coverage to meaningless boiler code that sits in the application code merely to shut the compiler up.<BR/>And hey, it has to be done in all method. Now I've long stopped doing unit-test to catch block except if it contains meaningful business logic. I.e., I let most of the code-block sit red on coverage report. Thus, almost none of my methods has 100% coverage.Hendry Lukhttps://www.blogger.com/profile/16180027255687806862noreply@blogger.com