<?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"
	>
<channel>
	<title>Comments on: One Mock Per Test</title>
	<atom:link href="http://laribee.com/blog/2007/08/04/one-mock-per-test/feed/" rel="self" type="application/rss+xml" />
	<link>http://laribee.com/blog/2007/08/04/one-mock-per-test/</link>
	<description>Coaching, Process, Design, Speculation</description>
	<pubDate>Sat, 22 Nov 2008 07:40:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Ben Scheirman</title>
		<link>http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24972</link>
		<dc:creator>Ben Scheirman</dc:creator>
		<pubDate>Mon, 06 Aug 2007 13:14:17 +0000</pubDate>
		<guid isPermaLink="false">http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24972</guid>
		<description>Good info.  This has been my current pain point with mocks, so I will try breaking them apart and get back into rhythm.

Thanks!</description>
		<content:encoded><![CDATA[<p>Good info.  This has been my current pain point with mocks, so I will try breaking them apart and get back into rhythm.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Jensen</title>
		<link>http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24825</link>
		<dc:creator>Aaron Jensen</dc:creator>
		<pubDate>Sun, 05 Aug 2007 23:43:23 +0000</pubDate>
		<guid isPermaLink="false">http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24825</guid>
		<description>Yeah, everything that the AMC resolves is a singleton. It's then cached so that you can retrieve it with Get&#60;T&#62;();. You can also call Get before you ever do a Create if you need to set up those mocks before the constructor.</description>
		<content:encoded><![CDATA[<p>Yeah, everything that the AMC resolves is a singleton. It&#8217;s then cached so that you can retrieve it with Get&lt;T&gt;();. You can also call Get before you ever do a Create if you need to set up those mocks before the constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24822</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sun, 05 Aug 2007 23:11:36 +0000</pubDate>
		<guid isPermaLink="false">http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24822</guid>
		<description>@Aaron - nevermind, the service is reg'd singleton.</description>
		<content:encoded><![CDATA[<p>@Aaron - nevermind, the service is reg&#8217;d singleton.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24657</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sun, 05 Aug 2007 13:34:11 +0000</pubDate>
		<guid isPermaLink="false">http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24657</guid>
		<description>That is much nicer! (And a good point re: DynamicMocks.) I hope people will focus on the content after "so what’s the benefit of the single mock approach?" 

You would use your container to resolve the service dependency transitively? I guess why not if you use the AMC...</description>
		<content:encoded><![CDATA[<p>That is much nicer! (And a good point re: DynamicMocks.) I hope people will focus on the content after &#8220;so what’s the benefit of the single mock approach?&#8221; </p>
<p>You would use your container to resolve the service dependency transitively? I guess why not if you use the AMC&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Jensen</title>
		<link>http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24637</link>
		<dc:creator>Aaron Jensen</dc:creator>
		<pubDate>Sun, 05 Aug 2007 10:30:10 +0000</pubDate>
		<guid isPermaLink="false">http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24637</guid>
		<description>Erg my generic type specifies didn't show up... replace all the Gets with Get&#60;ISearchService&#62;</description>
		<content:encoded><![CDATA[<p>Erg my generic type specifies didn&#8217;t show up&#8230; replace all the Gets with Get&lt;ISearchService&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Jensen</title>
		<link>http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24636</link>
		<dc:creator>Aaron Jensen</dc:creator>
		<pubDate>Sun, 05 Aug 2007 10:28:54 +0000</pubDate>
		<guid isPermaLink="false">http://laribee.com/blog/2007/08/04/one-mock-per-test/#comment-24636</guid>
		<description>I agree with most of what you said, however I don't know that alternating between stubs and mocks in your tests really adds any value. If you just use dynamic mocks for everything, which is the default if you're using the AutoMockingContainer (another post on that coming soon), you'll get pretty much the same 1 "assertion" per test you're wanting by using mocks. 

The key is liberal usage of SetupResult.For() and LastCall.PropertyBehavior(). Just be sure to Expect.Call() anything you actually want to be called (and verify it). The benefit is that you can simplify the way your tests look... you just always construct the subject under test with the same dynamic mocks (or that happens automatically w/ AMC) rather than declaring stubs and substituting mocks when you need to. 

Dynamic"Mocks" are "stubs" until you tell them not to be... for the most intents and purposes.

I mean... isn't this nicer:
private MockRepository _mocks;
private AutoMockingContainer _container;
private SearchPresenter _presenter;
private SearchResultDTO _fakeResults;

[SetUp]
public void Setup()
{
  this._mocks = new MockRepository();
  this._container = new AutoMockingContainer(_mocks);
  this._presenter = _container.Create();
  this._fakeResults = new SearchResultDTO();
}

[Test]
public void Can_search_for_customers_by_number_of_orders()
{
  using (_mocks.Record())
  {
    Expect
     .Call(_container.Get().GetCustomersByOrderCount(42))
     .Return(this._fakeResults);
  }

  using (_mocks.Playback())
  {
    _presenter.SearchByOrderCount(42);
  }
}

[Test]
public void Search_results_are_displayed_to_the_user()
{
  using (_mocks.Record())
  {
    mockView.SearchResults = _fakeResults;
    SetupResult
     .For(_container.Get().GetCustomersByOrderCount(42))
     .Return(_fakeResults);
  }

  using (_mocks.Playback())
  {
    presenter.SearchByOrderCount(42);
  }
}</description>
		<content:encoded><![CDATA[<p>I agree with most of what you said, however I don&#8217;t know that alternating between stubs and mocks in your tests really adds any value. If you just use dynamic mocks for everything, which is the default if you&#8217;re using the AutoMockingContainer (another post on that coming soon), you&#8217;ll get pretty much the same 1 &#8220;assertion&#8221; per test you&#8217;re wanting by using mocks. </p>
<p>The key is liberal usage of SetupResult.For() and LastCall.PropertyBehavior(). Just be sure to Expect.Call() anything you actually want to be called (and verify it). The benefit is that you can simplify the way your tests look&#8230; you just always construct the subject under test with the same dynamic mocks (or that happens automatically w/ AMC) rather than declaring stubs and substituting mocks when you need to. </p>
<p>Dynamic&#8221;Mocks&#8221; are &#8220;stubs&#8221; until you tell them not to be&#8230; for the most intents and purposes.</p>
<p>I mean&#8230; isn&#8217;t this nicer:<br />
private MockRepository _mocks;<br />
private AutoMockingContainer _container;<br />
private SearchPresenter _presenter;<br />
private SearchResultDTO _fakeResults;</p>
<p>[SetUp]<br />
public void Setup()<br />
{<br />
  this._mocks = new MockRepository();<br />
  this._container = new AutoMockingContainer(_mocks);<br />
  this._presenter = _container.Create();<br />
  this._fakeResults = new SearchResultDTO();<br />
}</p>
<p>[Test]<br />
public void Can_search_for_customers_by_number_of_orders()<br />
{<br />
  using (_mocks.Record())<br />
  {<br />
    Expect<br />
     .Call(_container.Get().GetCustomersByOrderCount(42))<br />
     .Return(this._fakeResults);<br />
  }</p>
<p>  using (_mocks.Playback())<br />
  {<br />
    _presenter.SearchByOrderCount(42);<br />
  }<br />
}</p>
<p>[Test]<br />
public void Search_results_are_displayed_to_the_user()<br />
{<br />
  using (_mocks.Record())<br />
  {<br />
    mockView.SearchResults = _fakeResults;<br />
    SetupResult<br />
     .For(_container.Get().GetCustomersByOrderCount(42))<br />
     .Return(_fakeResults);<br />
  }</p>
<p>  using (_mocks.Playback())<br />
  {<br />
    presenter.SearchByOrderCount(42);<br />
  }<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
