<?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: Fakes and Mocks and Stubs, Oh My!!!</title>
	<atom:link href="http://theshyam.com/2008/08/fakes-and-mocks-and-stubs-oh-my/feed/" rel="self" type="application/rss+xml" />
	<link>http://theshyam.com/2008/08/fakes-and-mocks-and-stubs-oh-my/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fakes-and-mocks-and-stubs-oh-my</link>
	<description>Ramblings from the Real Shyam; You know, unlike those other fake Shyams!</description>
	<lastBuildDate>Sat, 28 Jan 2012 06:10:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Shyam</title>
		<link>http://theshyam.com/2008/08/fakes-and-mocks-and-stubs-oh-my/#comment-35</link>
		<dc:creator>Shyam</dc:creator>
		<pubDate>Tue, 18 Aug 2009 16:50:51 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=42#comment-35</guid>
		<description>@Gabriel

So this is something I run into quite often, and in my experience, the classes which just delegate to other services aren&#039;t really worth testing that well. At best, test that it passes down the right parameters, and assume that the service you are delegating to is well tested and does what it should. If that service is one of your own, test that thoroughly instead. And most of all, have some integration tests which test the entire thing.

Like if you are delegating to something that talks to a database, maybe have a test which has an actual (or fake db) at the back, and tests that this delegates properly and returns the right thing. But on the unit test level, have maybe one test per delegation, and leave it at that. 

Hope that helps.</description>
		<content:encoded><![CDATA[<p>@Gabriel</p>
<p>So this is something I run into quite often, and in my experience, the classes which just delegate to other services aren&#8217;t really worth testing that well. At best, test that it passes down the right parameters, and assume that the service you are delegating to is well tested and does what it should. If that service is one of your own, test that thoroughly instead. And most of all, have some integration tests which test the entire thing.</p>
<p>Like if you are delegating to something that talks to a database, maybe have a test which has an actual (or fake db) at the back, and tests that this delegates properly and returns the right thing. But on the unit test level, have maybe one test per delegation, and leave it at that. </p>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel</title>
		<link>http://theshyam.com/2008/08/fakes-and-mocks-and-stubs-oh-my/#comment-34</link>
		<dc:creator>Gabriel</dc:creator>
		<pubDate>Mon, 17 Aug 2009 21:43:47 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=42#comment-34</guid>
		<description>Hi,

I&#039;ve been getting in to unit testing these past months and have been browsing around for any tips, best practices and so on I can read. I found this post today and in the disadvantages about Mocks you mentioned something that has been bothering me these past few days. I feel that some of the tests I wrote with mocks are mostly testing the interaction between the mocks and depend too much on the implementation! Do you have any advice on how can this be avoided? Some methods are just delegating to other collaborators and I&#039;m not sure how to test them properly.

Thanks in advance. :)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;ve been getting in to unit testing these past months and have been browsing around for any tips, best practices and so on I can read. I found this post today and in the disadvantages about Mocks you mentioned something that has been bothering me these past few days. I feel that some of the tests I wrote with mocks are mostly testing the interaction between the mocks and depend too much on the implementation! Do you have any advice on how can this be avoided? Some methods are just delegating to other collaborators and I&#8217;m not sure how to test them properly.</p>
<p>Thanks in advance. <img src='http://theshyam.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: closingbraces</title>
		<link>http://theshyam.com/2008/08/fakes-and-mocks-and-stubs-oh-my/#comment-33</link>
		<dc:creator>closingbraces</dc:creator>
		<pubDate>Fri, 22 Aug 2008 23:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=42#comment-33</guid>
		<description>Shyam,

I see what you mean about the possible work involved in configuring a fake DB, as opposed to mocking it. Guess a lot depends on the nature of what&#039;s being faked, as well as what facilities the fake provides and how well it&#039;s been done.

Absolutely agree about using whatever&#039;s best for each situation. I see far too much clutching at names and silver bullets these days, rather than thinking about what precisely is needed in each specific situation. Probably guilty of that myself at times, but do try to avoid it.</description>
		<content:encoded><![CDATA[<p>Shyam,</p>
<p>I see what you mean about the possible work involved in configuring a fake DB, as opposed to mocking it. Guess a lot depends on the nature of what&#8217;s being faked, as well as what facilities the fake provides and how well it&#8217;s been done.</p>
<p>Absolutely agree about using whatever&#8217;s best for each situation. I see far too much clutching at names and silver bullets these days, rather than thinking about what precisely is needed in each specific situation. Probably guilty of that myself at times, but do try to avoid it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shyamseshadri</title>
		<link>http://theshyam.com/2008/08/fakes-and-mocks-and-stubs-oh-my/#comment-32</link>
		<dc:creator>shyamseshadri</dc:creator>
		<pubDate>Fri, 22 Aug 2008 20:18:08 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=42#comment-32</guid>
		<description>I agree with you on the fact that Fakes are the most ideal of the lot. It gives you the closest test to an integration test while still being an unit test. And yeah, Fakes are generally fast, but compared to Mocks and stubs, not so much. But I&#039;ll play devil&#039;s advocate here.

Fakes can (can, and not necessarily must) be hard to setup to work similar to an existing service. Also, to test the interesting cases with a Fake, you might need to get the, say FakeDB, into a particular state before you can do your actual test. These might be like adding specific rows, and getting the DB to a particular state. Whereas with a mock, you can just tell it to expect a call and return whatever you need it to. (Stubs of course, can never do this...). Also might be tough to use a Fake Http service and stuff (not impossible, but harder than it needs to be).

In the end, I feel it comes down to using what is most ideal for the situation. Use Fakes whenever you can, and whenever time and complexity permits, but use Mocks to get things going quickly and if you want to test edge cases easily and use stubs if you need to just get through the offending material.</description>
		<content:encoded><![CDATA[<p>I agree with you on the fact that Fakes are the most ideal of the lot. It gives you the closest test to an integration test while still being an unit test. And yeah, Fakes are generally fast, but compared to Mocks and stubs, not so much. But I&#8217;ll play devil&#8217;s advocate here.</p>
<p>Fakes can (can, and not necessarily must) be hard to setup to work similar to an existing service. Also, to test the interesting cases with a Fake, you might need to get the, say FakeDB, into a particular state before you can do your actual test. These might be like adding specific rows, and getting the DB to a particular state. Whereas with a mock, you can just tell it to expect a call and return whatever you need it to. (Stubs of course, can never do this&#8230;). Also might be tough to use a Fake Http service and stuff (not impossible, but harder than it needs to be).</p>
<p>In the end, I feel it comes down to using what is most ideal for the situation. Use Fakes whenever you can, and whenever time and complexity permits, but use Mocks to get things going quickly and if you want to test edge cases easily and use stubs if you need to just get through the offending material.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: closingbraces</title>
		<link>http://theshyam.com/2008/08/fakes-and-mocks-and-stubs-oh-my/#comment-31</link>
		<dc:creator>closingbraces</dc:creator>
		<pubDate>Thu, 21 Aug 2008 23:38:25 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=42#comment-31</guid>
		<description>Thanks for the good article - a very clear summary of the differences.

My own take on &quot;fakes&quot; is that it can indeed be a lot of work to create really good fakes (including testing them, as you point out). But for widely used API or services I think it can make sense for someone to do this centrally, and produce a library of &quot;ideal&quot; fakes for that API. Everyone else can then just use the pre-written, pre-tested fakes.

Ideally I&#039;d like to see this as a responsibility of API design and implementation. If an API actually needs test-doubles or a fake service in order to be easily testable, the API ought to supply this. And this ought to be taken into account in the API design (e.g. avoid needing it if possible, or make it as straightforward as possible). Well, we can all dream...

In terms of speed, if a fake is just doing normal in-memory stuff, it might involve slightly more than a mock but this shouldn&#039;t normally be so much as to impact performance. You can churn through an awful lot of &quot;plain&quot; code before noticing any impact, and the code that you&#039;re testing probably does as much or more than the fake. At least that&#039;s been my experience.

I&#039;d say defining expectations is different for a fake, rather than harder, with a lot depending on the precise nature of the fake. If the fake lets you configure and inspect everything relevant to the object&#039;s behaviour, and can record the API calls too, then you&#039;ve got eveything you need. I don&#039;t think there has to be anything making it intrinsically harder than strictly necessary.

So on the whole I tend to regard &quot;fakes&quot; as the ideal - if you can get someone to develop them for you!

At any rate, that&#039;s my personal view on fakes, based on writing a set for the Servlet API.

Mike</description>
		<content:encoded><![CDATA[<p>Thanks for the good article &#8211; a very clear summary of the differences.</p>
<p>My own take on &#8220;fakes&#8221; is that it can indeed be a lot of work to create really good fakes (including testing them, as you point out). But for widely used API or services I think it can make sense for someone to do this centrally, and produce a library of &#8220;ideal&#8221; fakes for that API. Everyone else can then just use the pre-written, pre-tested fakes.</p>
<p>Ideally I&#8217;d like to see this as a responsibility of API design and implementation. If an API actually needs test-doubles or a fake service in order to be easily testable, the API ought to supply this. And this ought to be taken into account in the API design (e.g. avoid needing it if possible, or make it as straightforward as possible). Well, we can all dream&#8230;</p>
<p>In terms of speed, if a fake is just doing normal in-memory stuff, it might involve slightly more than a mock but this shouldn&#8217;t normally be so much as to impact performance. You can churn through an awful lot of &#8220;plain&#8221; code before noticing any impact, and the code that you&#8217;re testing probably does as much or more than the fake. At least that&#8217;s been my experience.</p>
<p>I&#8217;d say defining expectations is different for a fake, rather than harder, with a lot depending on the precise nature of the fake. If the fake lets you configure and inspect everything relevant to the object&#8217;s behaviour, and can record the API calls too, then you&#8217;ve got eveything you need. I don&#8217;t think there has to be anything making it intrinsically harder than strictly necessary.</p>
<p>So on the whole I tend to regard &#8220;fakes&#8221; as the ideal &#8211; if you can get someone to develop them for you!</p>
<p>At any rate, that&#8217;s my personal view on fakes, based on writing a set for the Servlet API.</p>
<p>Mike</p>
]]></content:encoded>
	</item>
</channel>
</rss>

