Are too many assertions code smell?

Posted by Florents on Programmers See other posts from Programmers or by Florents
Published on 2012-06-18T22:45:12Z Indexed on 2012/06/19 3:23 UTC
Read the original article Hit count: 322

I've really fallen in love with unit testing and TDD - I am test infected.

However, unit testing is used for public methods. Sometimes though I do have to test some assumptions-assertions in private methods too, because some of them are "dangerous" and refactoring can't help further. (I know, testing frameworks allo testing private methods).

So, It became a habit of mine that (almost always) the first and the last line of a private method are both assertions. I guess this couldn't be bad (right ??).

However, I've noticed that I also tend to use assertions in public methods too (as in the private) just "to be sure". Could this be "testing duplication" since the public method assumpotions are tested from the unit testng framework?

Could someone think of too many assertions as a code smell?

© Programmers or respective owner

Related posts about testing

Related posts about code-quality