Sign up to receive your copy of the JavaRanch Journal.

productivity award
 

Evil Unit Testing

by Paul Wheaton

As a contractor, I have now appeared at no less than six different companies beaming with pride that they have "unit testing"! And, combined with that great pride is concern that this "unit testing" is turning out to be a hassle. "Other people talk about how great unit testing is, but this is really becoming painful. The tests take 45 minutes to run, and for every little change to the code, we break about seven tests!"

What these folks have is a massive pile of functional tests. They fell into the popular trap of thinking that because they run the tests with JUnit, they must be unit tests. 90% of their problems could have been resolved with just a wee bit of vocabulary.

Software Testing Vocabulary


To clarify the number one struggle shops have with "unit testing":

The Trouble With Too Many Functional Tests


Making good unit tests requires an understanding of

Unit Testing Mock Basics


To get an idea of how a project might keep all of this stuff straight, take a gander at a

Sample Directory Structure


Fin

This is just a quick overview of this topic. But once you have your head wrapped around this, you're ready for

  • continuous integration
  • ant
  • improving your layer interfaces while not sacrificing testability (static methods using inner implementation classes)
  • testing one class or one test method from your IDE
  • test first development (sometimes called test driven development) - should you do it more, than, say 30% of the time?
  • Extreme Programming!
  • Fitnesse






 


-