Unit Testing Gives Merit to Design Patterns

An entry about tdd | design patterns Publication date 8. December 2008 23:58

Son Hui has written a post in which he shows how using TypeMock helps him mock the SmtpClient class. At the beginning of his post, he writes:

“The proponents of TDD would like to use Dependency Injection(DI) technique to inject the SmtpClient dependencies into the mail sending class in order to facilitate unit testing.“

I would much rather say that the reason we do dependency injection is to achieve what is called the dependency inversion principle. I think this is one of the biggest misconceptions a lot of people have when faced with unit testing: the idea that in order to make code testable, they have to apply all of these academic design patterns. But, isn't´t just the fact that these design patterns makes code easier to test just more proof that they actually work?

Go SOLID today.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Powered by BlogEngine.NET 1.4.5.0

Welcome!

My name is Fredrik Kalseth, and this is my blog - thanks for visiting! I am fortunate enough to work with what I love for a living, and this blog is essentially the biproduct of that.

I work as a senior consultant for Capgemini, and am also an active participant in the Norwegian .NET community, as an avid attendee but also as a speaker (most recently at NNUG and MSDN Live).

As a developer, I have a wide circle of interest. My primary passion is for agile, test-driven development, with focus on best practices and clean code. That said, I also love to work on the frontend, especially with web development.

On Twitter? My handle is fkalseth. On LinkedIn? I`m there too.

Disclaimer

This is a personal blog; any opinions expressed here are my own and do not necessarily reflect those of my employer. All content herein is my own original creation, and as such is protected by copyright law. Unless otherwise stated, all source code posted on this blog is freely usable under the Microsoft Permissive License.

What Readers Talk About

Comment RSS