<?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: Rhino Mocks Examples, with a fix</title>
	<atom:link href="http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/</link>
	<description>Sharon Cichelli&#039;s blog about software, development, teams, and projects</description>
	<lastBuildDate>Wed, 13 Mar 2013 20:15:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Mathias</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-27</link>
		<dc:creator>Mathias</dc:creator>
		<pubDate>Mon, 22 Mar 2010 05:17:46 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-27</guid>
		<description>Great post; I have struggled with exactly the same issue, and Rhino.Mocks API doesn&#039;t help understand the difference between Mocks and Stubs, because they both support the same methods, and stubs fail silently. Personally, the aha moment for me came when I read Roy Osherove&#039;s &quot;The Art of Unit Testing&quot;, where he states that a test could fail because of a Mock, but never because of a Stub. That doesn&#039;t resolve the somewhat ambiguous API issues, but that helps in determining whether what you need is a Mock or a Stub!</description>
		<content:encoded><![CDATA[<p>Great post; I have struggled with exactly the same issue, and Rhino.Mocks API doesn&#8217;t help understand the difference between Mocks and Stubs, because they both support the same methods, and stubs fail silently. Personally, the aha moment for me came when I read Roy Osherove&#8217;s &#8220;The Art of Unit Testing&#8221;, where he states that a test could fail because of a Mock, but never because of a Stub. That doesn&#8217;t resolve the somewhat ambiguous API issues, but that helps in determining whether what you need is a Mock or a Stub!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Kruger</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-26</link>
		<dc:creator>Jon Kruger</dc:creator>
		<pubDate>Mon, 22 Mar 2010 02:14:42 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-26</guid>
		<description>I updated my original post to fix the problem that you pointed out in this post.  Thanks for pointing that out.

Jon</description>
		<content:encoded><![CDATA[<p>I updated my original post to fix the problem that you pointed out in this post.  Thanks for pointing that out.</p>
<p>Jon</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Eyde</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-25</link>
		<dc:creator>Thomas Eyde</dc:creator>
		<pubDate>Sun, 21 Mar 2010 12:56:04 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-25</guid>
		<description>@Arthur, we can always debate whether an api is broken or not. But extension methods can operate on different types. My argument is that GenerateMock and GenerateStub should return different types. When that&#039;s the case, we can have extension methods which only operates on one of the types.

@Krzysztof, you are correct. It&#039;s easy to make the same mistake in Moq. I don&#039;t use Verify very often, so I didn&#039;t know. In that respect, I should probably refrain from commenting.

One can also argue that the Moq api is broken. I don&#039;t know the rationale behind Verifiable(), but from where I am sitting, every method should be so by default. It&#039;s up to me to call Verify() at the end.</description>
		<content:encoded><![CDATA[<p>@Arthur, we can always debate whether an api is broken or not. But extension methods can operate on different types. My argument is that GenerateMock and GenerateStub should return different types. When that&#8217;s the case, we can have extension methods which only operates on one of the types.</p>
<p>@Krzysztof, you are correct. It&#8217;s easy to make the same mistake in Moq. I don&#8217;t use Verify very often, so I didn&#8217;t know. In that respect, I should probably refrain from commenting.</p>
<p>One can also argue that the Moq api is broken. I don&#8217;t know the rationale behind Verifiable(), but from where I am sitting, every method should be so by default. It&#8217;s up to me to call Verify() at the end.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Svihla</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-24</link>
		<dc:creator>Ryan Svihla</dc:creator>
		<pubDate>Sat, 20 Mar 2010 23:38:59 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-24</guid>
		<description>For the kinds of test I really prefer obj.AssertWasCalled(x=&gt;x.WhateverMethod), Then I can write asserts against specific method calls.  Also with this approach I never have to use Expect and I only need Stub for my return values.

Ayende has examples of the AssertWasCalled approach in many places but here is one:
http://ayende.com/Blog/archive/2008/05/16/Rhino-Mocks--Arrange-Act-Assert-Syntax.aspx</description>
		<content:encoded><![CDATA[<p>For the kinds of test I really prefer obj.AssertWasCalled(x=>x.WhateverMethod), Then I can write asserts against specific method calls.  Also with this approach I never have to use Expect and I only need Stub for my return values.</p>
<p>Ayende has examples of the AssertWasCalled approach in many places but here is one:<br />
<a href="http://ayende.com/Blog/archive/2008/05/16/Rhino-Mocks--Arrange-Act-Assert-Syntax.aspx" rel="nofollow">http://ayende.com/Blog/archive/2008/05/16/Rhino-Mocks&#8211;Arrange-Act-Assert-Syntax.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Artur Dorochowicz</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-23</link>
		<dc:creator>Artur Dorochowicz</dc:creator>
		<pubDate>Fri, 19 Mar 2010 17:45:11 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-23</guid>
		<description>Expect, Assert..., Verify... are implemented as extension methods on object. That&#039;s the only way you can make it work in C#.
So certainly, Rhino Mocks API is not broken.</description>
		<content:encoded><![CDATA[<p>Expect, Assert&#8230;, Verify&#8230; are implemented as extension methods on object. That&#8217;s the only way you can make it work in C#.<br />
So certainly, Rhino Mocks API is not broken.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MM</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-22</link>
		<dc:creator>MM</dc:creator>
		<pubDate>Fri, 19 Mar 2010 14:41:20 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-22</guid>
		<description>@Krzysztof - But don&#039;t you think that this &quot;shortcoming&quot; is a little bit more acceptable in Moq because there is only one type of fake? In Rhino Mocks, stub and mock are distinct types so why even put the verify methods on stubs? I think the Moq documentation makes it fairly clear that Verify() will only verify expectations marked as Verifiable (then again, maybe the Rhino Mocks docs make it clear that you should not verify stubs).

John Sonmez hit the nail on the head. The bottom is line is that this is a good reminder that we should always make sure that our tests fail when they are supposed to.</description>
		<content:encoded><![CDATA[<p>@Krzysztof &#8211; But don&#8217;t you think that this &#8220;shortcoming&#8221; is a little bit more acceptable in Moq because there is only one type of fake? In Rhino Mocks, stub and mock are distinct types so why even put the verify methods on stubs? I think the Moq documentation makes it fairly clear that Verify() will only verify expectations marked as Verifiable (then again, maybe the Rhino Mocks docs make it clear that you should not verify stubs).</p>
<p>John Sonmez hit the nail on the head. The bottom is line is that this is a good reminder that we should always make sure that our tests fail when they are supposed to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-21</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Fri, 19 Mar 2010 14:22:32 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-21</guid>
		<description>Good catch.  I think the bigger problem is though it not this incidence, but of not making sure that a test can fail.  I wrote about this here: http://simpleprogrammer.com/2010/03/05/the-ego-test/

I call it an &quot;ego test&quot;, because you can always run it and feel good.

The only way to really prevent these kinds of problems is to make sure you can make a test fail.</description>
		<content:encoded><![CDATA[<p>Good catch.  I think the bigger problem is though it not this incidence, but of not making sure that a test can fail.  I wrote about this here: <a href="http://simpleprogrammer.com/2010/03/05/the-ego-test/" rel="nofollow">http://simpleprogrammer.com/2010/03/05/the-ego-test/</a></p>
<p>I call it an &#8220;ego test&#8221;, because you can always run it and feel good.</p>
<p>The only way to really prevent these kinds of problems is to make sure you can make a test fail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Kruger</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-20</link>
		<dc:creator>Jon Kruger</dc:creator>
		<pubDate>Fri, 19 Mar 2010 12:51:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-20</guid>
		<description>Interesting.  I was trying to figure out the differences between GenerateStub() and GenerateMock() and you pointed out one that I missed.  I know what the difference is between a stub and a mock (from an academic perspective), but in Rhino Mocks I find that I never use GenerateMock().  Now, I don&#039;t ever use Expect() and VerifyAllExpectations(), I prefer AssertWasCalled() instead, but that&#039;s just my preference (and probably why I never found this problem before).

Looks like I&#039;ll have to go update my code (unless you want to send me a patch!).</description>
		<content:encoded><![CDATA[<p>Interesting.  I was trying to figure out the differences between GenerateStub() and GenerateMock() and you pointed out one that I missed.  I know what the difference is between a stub and a mock (from an academic perspective), but in Rhino Mocks I find that I never use GenerateMock().  Now, I don&#8217;t ever use Expect() and VerifyAllExpectations(), I prefer AssertWasCalled() instead, but that&#8217;s just my preference (and probably why I never found this problem before).</p>
<p>Looks like I&#8217;ll have to go update my code (unless you want to send me a patch!).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krzysztof Kozmic</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-19</link>
		<dc:creator>Krzysztof Kozmic</dc:creator>
		<pubDate>Fri, 19 Mar 2010 11:48:20 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-19</guid>
		<description>Thomas

You can fall prey to this issue with MoQ as easily as with Rhino Mocks.

        [Test]
        public void Moq()
        {
            var mock = new Mock&lt;IFoo&gt;();

            mock.Setup( m =&gt; m.GetFoo() ).Returns( 34 );

            //mock.Object.GetFoo();

            mock.Verify();
        }

    public interface IFoo
    {
        int GetFoo();
    }

This test will pass although it clearly shouldn&#039;t (it does what I told it to, not what I wanted it to do).

It&#039;s your choice if you like one framework over another but it has nothing to do with the issue at hand.</description>
		<content:encoded><![CDATA[<p>Thomas</p>
<p>You can fall prey to this issue with MoQ as easily as with Rhino Mocks.</p>
<p>        [Test]<br />
        public void Moq()<br />
        {<br />
            var mock = new Mock<ifoo>();</p>
<p>            mock.Setup( m => m.GetFoo() ).Returns( 34 );</p>
<p>            //mock.Object.GetFoo();</p>
<p>            mock.Verify();<br />
        }</p>
<p>    public interface IFoo<br />
    {<br />
        int GetFoo();<br />
    }</p>
<p>This test will pass although it clearly shouldn&#8217;t (it does what I told it to, not what I wanted it to do).</p>
<p>It&#8217;s your choice if you like one framework over another but it has nothing to do with the issue at hand.</ifoo></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Eyde</title>
		<link>http://lostechies.com/sharoncichelli/2010/03/19/rhino-mocks-examples-with-a-fix/#comment-18</link>
		<dc:creator>Thomas Eyde</dc:creator>
		<pubDate>Fri, 19 Mar 2010 08:54:32 +0000</pubDate>
		<guid isPermaLink="false">/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx#comment-18</guid>
		<description>Or we can use a mocking framework with a lesser confusing api. My favourite for the moment is Moq. I haven&#039;t used Rhino Mock since its Record / Replay days, and I failed miserably using that pattern. 

I can relate to Stubs aren&#039;t Mocks, but why should the framework care? For me, the test dummy is a stub when I use it as a stub. If I later choose to use it as a mock, then it is a mock.

We can debate this issue for as long as we want, but the fact remains that the Rhino Mock API is broken: The non-working VerifyAllExpectations()-method should never have been there in the first place.</description>
		<content:encoded><![CDATA[<p>Or we can use a mocking framework with a lesser confusing api. My favourite for the moment is Moq. I haven&#8217;t used Rhino Mock since its Record / Replay days, and I failed miserably using that pattern. </p>
<p>I can relate to Stubs aren&#8217;t Mocks, but why should the framework care? For me, the test dummy is a stub when I use it as a stub. If I later choose to use it as a mock, then it is a mock.</p>
<p>We can debate this issue for as long as we want, but the fact remains that the Rhino Mock API is broken: The non-working VerifyAllExpectations()-method should never have been there in the first place.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
