In chemistry or in physics if you are making some experiments you are putting the subject in a controlled environment.
You do it because you want to avoid external complexity and side effects.

The same thing we do in software development by mocking interaction partners of the unit under test.

Software, in particularly object oriented program, is all about communication. Every method call (message passing) is a communication. You passing some arguments and receiving values or exceptions. Your behavior depends on your communication partners because your algorithm will take different paths because of the return value or a thrown exception.

So if you want to make sure that the behavior is all good, you have to control what your partners are telling you. It is a part of the test scenario and of precondition to specify what will be received by the unit under test.

Another side effect that can be checked by a controlled environment is what your unit under test is telling it’s communication partners. That could be some computed values that you can’t check after the whole algorithm is executed.

If you make a Sequence diagram of the unit you are testing you should see all the communication options you have.
There you can also see if the communication can be controlled. If the communication partner is created by the algorithm under test you have no chance to controls its output and validate call parameters that are passed to it.

In this case a field and IoC is your friend. Same thing applies to Law of Demeter. It is easier to stub / control if you Only talk to your immediate friends and not to the friends of friends because in this way you also have to control friends of friends.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Before you submit form:
Human test by Not Captcha

© 2011 Max Blog Suffusion theme by Sayontan Sinha