<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Roadblock to Mocking Unit Tests</title>
	<atom:link href="http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/</link>
	<description>Improving my craft...</description>
	<lastBuildDate>Wed, 11 Aug 2010 17:07:39 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: cromwellryan</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-509</link>
		<dc:creator>cromwellryan</dc:creator>
		<pubDate>Tue, 15 Jul 2008 20:04:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-509</guid>
		<description>&lt;p&gt;Jeff, &lt;/p&gt;
&lt;p&gt;Believe I found the article (&lt;a rel=&quot;nofollow&quot; target=&quot;_new&quot; href=&quot;http://googletesting.blogspot.com/2008/06/defeat-static-cling.html&quot;&gt;googletesting.blogspot.com/.../defeat-static-cling.html&lt;/a&gt;) you were referring to. &#160;That is a great article. &#160;Wish I would have seen that a while ago. &#160;Thanks.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Jeff, </p>
<p>Believe I found the article (<a rel="nofollow" target="_new" href="http://googletesting.blogspot.com/2008/06/defeat-static-cling.html">googletesting.blogspot.com/&#8230;/defeat-static-cling.html</a>) you were referring to. &nbsp;That is a great article. &nbsp;Wish I would have seen that a while ago. &nbsp;Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Tucker</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-508</link>
		<dc:creator>Jeff Tucker</dc:creator>
		<pubDate>Tue, 15 Jul 2008 19:59:10 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-508</guid>
		<description>Here&#039;s a good post on the google test blog about &quot;static cling&quot; which I think would be helpful.  I&#039;ve found this solution to be highly useful in refactoring existing static cling.  Example is in java but should be readily applicable in .Net</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a good post on the google test blog about &#8220;static cling&#8221; which I think would be helpful.  I&#8217;ve found this solution to be highly useful in refactoring existing static cling.  Example is in java but should be readily applicable in .Net</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cromwellryan</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-507</link>
		<dc:creator>cromwellryan</dc:creator>
		<pubDate>Tue, 15 Jul 2008 19:49:51 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-507</guid>
		<description>hammett,

With Aarons series of comments walking me through these topics, I believe this is clearing up and I definitely take your point.  </description>
		<content:encoded><![CDATA[<p>hammett,</p>
<p>With Aarons series of comments walking me through these topics, I believe this is clearing up and I definitely take your point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hammett</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-506</link>
		<dc:creator>hammett</dc:creator>
		<pubDate>Tue, 15 Jul 2008 19:42:55 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-506</guid>
		<description>&gt; For instance, I can call Customer c = 
&gt; new Customer( &quot;Jon&quot;, &quot;Doe&quot; ) rather than 
&gt; Customer.Create(&quot;Jon&quot;, &quot;Doe&quot;).

Spring, windsor, whatever other ioc container shouldn&#039;t be used to create classes that represent the domain/state, they should only be concerned with providing services... 

</description>
		<content:encoded><![CDATA[<p>> For instance, I can call Customer c =<br />
> new Customer( &#8220;Jon&#8221;, &#8220;Doe&#8221; ) rather than<br />
> Customer.Create(&#8221;Jon&#8221;, &#8220;Doe&#8221;).</p>
<p>Spring, windsor, whatever other ioc container shouldn&#8217;t be used to create classes that represent the domain/state, they should only be concerned with providing services&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cromwellryan</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-505</link>
		<dc:creator>cromwellryan</dc:creator>
		<pubDate>Tue, 15 Jul 2008 19:38:33 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-505</guid>
		<description>I see what you are getting at.  The consumer of the Member.Register class has no real chance of easily Mocking the functionality provided by Register and is essentially forced to create a hard dependency, unless they create some wrapper.

I hadn&#039;t really  taken that into account.</description>
		<content:encoded><![CDATA[<p>I see what you are getting at.  The consumer of the Member.Register class has no real chance of easily Mocking the functionality provided by Register and is essentially forced to create a hard dependency, unless they create some wrapper.</p>
<p>I hadn&#8217;t really  taken that into account.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Jensen</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-504</link>
		<dc:creator>Aaron Jensen</dc:creator>
		<pubDate>Tue, 15 Jul 2008 19:29:34 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-504</guid>
		<description>It&#039;s not that it will cause increased coupling directly, but it enables developers to easily increase coupling. They don&#039;t need an instance, they just call a static method. This makes testing more convoluted and creates real dependencies that don&#039;t look like the other dependencies. That&#039;s a bad thing.</description>
		<content:encoded><![CDATA[<p>It&#8217;s not that it will cause increased coupling directly, but it enables developers to easily increase coupling. They don&#8217;t need an instance, they just call a static method. This makes testing more convoluted and creates real dependencies that don&#8217;t look like the other dependencies. That&#8217;s a bad thing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cromwellryan</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-503</link>
		<dc:creator>cromwellryan</dc:creator>
		<pubDate>Tue, 15 Jul 2008 19:10:52 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-503</guid>
		<description>I like your definition of the SRP on the Controller.  I think it is missing in most examples of Controllers and should be conveyed more prominently.

I&#039;ll have to give your Register example a run and see how things pan out.  I&#039;m not sure I see the increased coupling caused by static methods, but I will keep my eyes open as I attemp to understand and incorporate DDD into my repertoire.</description>
		<content:encoded><![CDATA[<p>I like your definition of the SRP on the Controller.  I think it is missing in most examples of Controllers and should be conveyed more prominently.</p>
<p>I&#8217;ll have to give your Register example a run and see how things pan out.  I&#8217;m not sure I see the increased coupling caused by static methods, but I will keep my eyes open as I attemp to understand and incorporate DDD into my repertoire.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Jensen</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-502</link>
		<dc:creator>Aaron Jensen</dc:creator>
		<pubDate>Tue, 15 Jul 2008 18:58:02 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-502</guid>
		<description>Ryan,

Regarding property injection (getters/setters) I&#039;d recommend steering away from that too. They are typically used for optional dependencies. An object should be able to function after its constructed.

And yes, unit testing tools (Nunit, mocking, whatever) are very useful for integration tests. They should be called testing tools rather than unit testing tools, but too late to change that :)

Glad to hear about the VerifyAll thing... it&#039;s currently one of my biggest annoyances with Mock frameworks--the poor guidance on mock vs. stub.

Static methods greatly increase coupling. You mention that they are there for &quot;ease of use by the developer&quot;. The unforutnate bit about that is by making it that easy you are likely to end up with a web of class dependencies and you can quickly get to an unmanageable mess. When your dependencies are explicit and few your code is even more navigable.

SRP on the BLL can be a bit awkward, you basically say that the responsibility is to act like a Whatever entity. If in your business domain entities have multiple responsibilites you either need to accept that or separate those entities into role based entities. You&#039;d especially do this if you have a bounded context between the roles or they&#039;re separate domains. 

SRP on the Controller is simple. Its responsibility is to delegate an action to the appropriate application service and do any adapting it needs to do to the parameters.

About implementing Register, I&#039;d probably just delegate to a factory to do the creation, save the user in the repository, and then delegate to an email sender to thank them. You could also fire a user registered message that an email sender would listen to and send the thank you email. That sort of architecture is very nice and its something we&#039;re trying to move to.</description>
		<content:encoded><![CDATA[<p>Ryan,</p>
<p>Regarding property injection (getters/setters) I&#8217;d recommend steering away from that too. They are typically used for optional dependencies. An object should be able to function after its constructed.</p>
<p>And yes, unit testing tools (Nunit, mocking, whatever) are very useful for integration tests. They should be called testing tools rather than unit testing tools, but too late to change that <img src='http://blog.cromwellhaus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Glad to hear about the VerifyAll thing&#8230; it&#8217;s currently one of my biggest annoyances with Mock frameworks&#8211;the poor guidance on mock vs. stub.</p>
<p>Static methods greatly increase coupling. You mention that they are there for &#8220;ease of use by the developer&#8221;. The unforutnate bit about that is by making it that easy you are likely to end up with a web of class dependencies and you can quickly get to an unmanageable mess. When your dependencies are explicit and few your code is even more navigable.</p>
<p>SRP on the BLL can be a bit awkward, you basically say that the responsibility is to act like a Whatever entity. If in your business domain entities have multiple responsibilites you either need to accept that or separate those entities into role based entities. You&#8217;d especially do this if you have a bounded context between the roles or they&#8217;re separate domains. </p>
<p>SRP on the Controller is simple. Its responsibility is to delegate an action to the appropriate application service and do any adapting it needs to do to the parameters.</p>
<p>About implementing Register, I&#8217;d probably just delegate to a factory to do the creation, save the user in the repository, and then delegate to an email sender to thank them. You could also fire a user registered message that an email sender would listen to and send the thank you email. That sort of architecture is very nice and its something we&#8217;re trying to move to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cromwellryan</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-501</link>
		<dc:creator>cromwellryan</dc:creator>
		<pubDate>Tue, 15 Jul 2008 18:22:12 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-501</guid>
		<description>Ben,
A quick scan of the Windsor documentation &quot;Wiring with constructors and properties&quot; (http://www.castleproject.org/container/documentation/v1rc3/usersguide/wiring.html) shows that Windsor supports Public Getter/Setters for passing dependencies.  I didn&#039;t realize that, but I don&#039;t know if that is any better.


Aaron (and now John),

Semantics... You are correct, I should be more clear.  I should say, I find the tools for Unit Testing helpful in running Integration Tests.

VerifyAll on the container... Oversight during copy paste.  I would not and don&#039;t include that assertion throughout.  There are unit tests specifically around my concrete container implementation, all one of them.

Single Responsibility... I would say that the API used throughout my application(s) do diverge from the Domain object purist vision.  I could easily see someone saying that my Customer object does too much orchestration, but I would vehemently argue that it does not leave the bounds of OO.  Do I use a CustomerRepository to get a customer, yes, inside my Customer.GetById static method.  I find it makes my API compact and navigable.

To the same point, Member.Register is a static method.  It isn&#039;t fully necessary for that to even exist and I could use DependencyInjection as it, internally, resolves an IRegistrationManager instance to do it&#039;s bidding.  Member.Register is simply their for ease of use by the developer.

Can I ask how you would recommend implementing the Register (my create) method or scenerio?  For the sake of the discussion, say Register simply Creates a member instances, sends them an email thanking them, and saves that instance to the Repository backing.

Can I also ask how you feel the SRP applies to a BLL or Controller?</description>
		<content:encoded><![CDATA[<p>Ben,<br />
A quick scan of the Windsor documentation &#8220;Wiring with constructors and properties&#8221; (<a href="http://www.castleproject.org/container/documentation/v1rc3/usersguide/wiring.html" rel="nofollow">http://www.castleproject.org/container/documentation/v1rc3/usersguide/wiring.html</a>) shows that Windsor supports Public Getter/Setters for passing dependencies.  I didn&#8217;t realize that, but I don&#8217;t know if that is any better.</p>
<p>Aaron (and now John),</p>
<p>Semantics&#8230; You are correct, I should be more clear.  I should say, I find the tools for Unit Testing helpful in running Integration Tests.</p>
<p>VerifyAll on the container&#8230; Oversight during copy paste.  I would not and don&#8217;t include that assertion throughout.  There are unit tests specifically around my concrete container implementation, all one of them.</p>
<p>Single Responsibility&#8230; I would say that the API used throughout my application(s) do diverge from the Domain object purist vision.  I could easily see someone saying that my Customer object does too much orchestration, but I would vehemently argue that it does not leave the bounds of OO.  Do I use a CustomerRepository to get a customer, yes, inside my Customer.GetById static method.  I find it makes my API compact and navigable.</p>
<p>To the same point, Member.Register is a static method.  It isn&#8217;t fully necessary for that to even exist and I could use DependencyInjection as it, internally, resolves an IRegistrationManager instance to do it&#8217;s bidding.  Member.Register is simply their for ease of use by the developer.</p>
<p>Can I ask how you would recommend implementing the Register (my create) method or scenerio?  For the sake of the discussion, say Register simply Creates a member instances, sends them an email thanking them, and saves that instance to the Repository backing.</p>
<p>Can I also ask how you feel the SRP applies to a BLL or Controller?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Teague</title>
		<link>http://blog.cromwellhaus.com/index.php/2008/07/roadblock-to-mocking-unit-tests/comment-page-1/#comment-500</link>
		<dc:creator>John Teague</dc:creator>
		<pubDate>Tue, 15 Jul 2008 18:13:13 +0000</pubDate>
		<guid isPermaLink="false">/blogs/ryanc/archive/2008/07/15/roadblock-to-mocking-unit-tests.aspx#comment-500</guid>
		<description>I think what Ben is saying (he&#039;ll correct me if I&#039;m wrong :-) is that you traded one tight coupling for another.  You&#039;re now coupled to your DI.  Does it have object lifecycle management? Do you really want to add that complexity to yours when you get it for free with other IOC containers?

What constructor injection gives you is removes your dependency on a specific implementation of your interface.  With Constructor Injection your NotificationManager can be changed for your testing or if you need to change it later.

Also, if your objects are indeed &quot;busy&quot; then you may want to consider if you&#039;re violating Single Responsibility Principle / Separation of Concerns.  It could be that your behavior should be broken up into smaller classes who have their own dependencies.

Single Responsibility Principle states that an object &quot;should have one reason to change.&quot;  Having a lot of dependencies in a class is my first smell that I&#039;m voilating this principle and I need to break up functionality.</description>
		<content:encoded><![CDATA[<p>I think what Ben is saying (he&#8217;ll correct me if I&#8217;m wrong <img src='http://blog.cromwellhaus.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  is that you traded one tight coupling for another.  You&#8217;re now coupled to your DI.  Does it have object lifecycle management? Do you really want to add that complexity to yours when you get it for free with other IOC containers?</p>
<p>What constructor injection gives you is removes your dependency on a specific implementation of your interface.  With Constructor Injection your NotificationManager can be changed for your testing or if you need to change it later.</p>
<p>Also, if your objects are indeed &#8220;busy&#8221; then you may want to consider if you&#8217;re violating Single Responsibility Principle / Separation of Concerns.  It could be that your behavior should be broken up into smaller classes who have their own dependencies.</p>
<p>Single Responsibility Principle states that an object &#8220;should have one reason to change.&#8221;  Having a lot of dependencies in a class is my first smell that I&#8217;m voilating this principle and I need to break up functionality.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
