Assigning Responsibilities

It’s All about Assigning Responsibilities

This example really hit home for me.  I am faced with a very similar legacy code design where some processing takes place and an e-mail is sent out.  My current tests consist of integration tests that outright send me an e-mail that I have to confirm manually.  Having these tests was far better than nothing at all, but their design never sat well with me.  They were from an earlier attempt at writing tests before I truly understood or had time to delve into IoC, mocks or refactoring for testability.

Now half a year after having written the tests, I understood that I could use a mock to determine if an e-mail was sent without sending an actual e-mail.  But how would that help me determine if the contents of the e-mail were correct.  After reading Jeremy's article it became clear that my code design itself was flawed and I need to simply separate the generation of the e-mail text from sending the e-mail.  It's such a simple idea and makes so much sense.

Share this post: Email it! | bookmark it! | digg it! | reddit!


Published Monday, January 14, 2008 8:04 AM by alecl
Filed under ,

Comments

 

Alec Lazarescu's Blog said:

A lot has been discussed on the pro's/con's of IoC for the purposes of unit testing and in general it

February 18, 2008 10:13 PM