Having personally developed lots of software as well as worked with many software developers over the years, I’ve formulated a theory on why lots of developers are resistant to unit testing and test driven development (TDD). The theory is simply that most developers know that 90% (or more) of the lines of code they write are defect free; consequently, forcing 100% of the code to have tests seems counterproductive to many of them. It’s a theory that seems obvious after being said out loud, but I rarely hear it explicitly verbalized in discussions to increase testing.
The mental hurdle that is difficult to overcome is that the 5-10% of the code with defects is like a minefield scattered throughout the product. Many Agile software processes promote a test first then code approach, and this considered a mythical utopia by most software shops. Even though more companies are adopting test first strategies, the key to changing the mindset has to occur in technical textbooks and classrooms. After the ‘hello’ program has been taught, all other examples should start with a test and proceed from there.