Rod Waldhoff's Weblog |
|
Unit tests with log statements are a code smell #
While this is not an earth shattering realization, I've come hold the opinion that log statements (log4j, logkit, java.util.logging, commons-logging, what have you) within unit tests are a code smell, perhaps universally. While I'll sometimes add a few System.out.println calls to a unit test while I'm trying to diagnose a particular failure, configuring a full-blown logging setup within a unit test always seemed like more time and trouble than it was worth. From time to time I'll encounter a heavily logged TestCase in some code base I'm working with. The more I work with such TestCases, the more I find this to be an indication that something is not right. Here's why:
* If you find yourself wanting programmatic inspection of log messages, I'll suggest you're looking for messaging, not logging. |
recent posts
Currently Reading
|