<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ketan&#039;s Musings &#187; mock</title>
	<atom:link href="http://ketan.padegaonkar.name/tag/mock/feed" rel="self" type="application/rss+xml" />
	<link>http://ketan.padegaonkar.name</link>
	<description>Where he blogs about his eclipse musings</description>
	<lastBuildDate>Fri, 23 Jul 2010 16:03:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Mockito &#8211; one of the better mocks</title>
		<link>http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html</link>
		<comments>http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html#comments</comments>
		<pubDate>Wed, 05 Mar 2008 13:54:51 +0000</pubDate>
		<dc:creator>Ketan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[mockito]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html</guid>
		<description><![CDATA[Now that I&#8217;ve got your attention. Mockito is not just better than the other mock frameworks out there, it&#8217;s infact the best out there. After reading a lot of noise from fellow ThoughtWorkers in the recent past about Mockito. I decided to give a yet another mock framework a try. Here&#8217;s what I ended up [...]]]></description>
			<content:encoded><![CDATA[<p>Now that I&#8217;ve got your attention. Mockito is not just better than the <a href="http://jmock.org">other</a> <a href="http://easymock.org">mock</a> frameworks out there, it&#8217;s infact the best out there.</p>
<p>After reading a lot of noise from <a href="http://sirenian.livejournal.com/45524.html">fellow</a> <a href="http://monkeyisland.pl/2008/01/14/mockito/">ThoughtWorkers</a> in the recent past about <a href="http://mockito.googlecode.com/">Mockito</a>. I decided to give a yet another mock framework a try.</p>
<p>Here&#8217;s what I ended up writing:</p>
<pre>public class RecorderLauncherTest extends TestCase {

	private RecorderListener listener;
	private RecorderLauncher launcher;
	private TestRunner runner;

	protected void setUp() throws Exception {
		super.setUp();
		listener = mock(RecorderListener.class);
		runner = mock(TestRunner.class);
		launcher = new RecorderLauncher(runner, listener);
	}

	public void testNotifiesListenerWhenLauncherStarts() throws Exception {
		launcher.launch();
		verify(listener).start();
	}

	public void testNotifiesListenerWhenExecutionFails() throws Exception {
		stubVoid(runner).toThrow(new RuntimeException()).on().run();
		launcher.launch();
		verify(listener).start();
		verify(listener).error();
	}

	public void testNotifiesListenerWhenExecutionCompletes() throws Exception {
		launcher.launch();
		verify(listener).start();
		verify(listener).finish();
	}

}</pre>
<p>What&#8217;s even nicer is that it&#8217;s actual code and not strings, and refactoring tests do not break my mocks.</p>
<p>Good bye <a href="http://monkeyisland.pl/2008/02/01/deathwish/">expect-run-verify</a>, hello run-verify.</p>
<p>This looks, and reads far better than the JMock syntax, and it was love at first sight; I&#8217;m test-infested now. If you have not tried mockito as yet, I&#8217;d recommend that you do. I&#8217;m sure you&#8217;ll love it too.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html&amp;title=Mockito+-+one+of+the+better+mocks" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html&amp;title=Mockito+-+one+of+the+better+mocks" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=RT+%40ketanpkr+Mockito+-+one+of+the+better+mocks+-+http://bit.ly/9wcA6z&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html&amp;t=Mockito+-+one+of+the+better+mocks" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-dzone">
			<a href="http://www.dzone.com/links/add.html?url=http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html&amp;title=Mockito+-+one+of+the+better+mocks&amp;description=Now%20that%20I%27ve%20got%20your%20attention.%20Mockito%20is%20not%20just%20better%20than%20the%20other%20mock%20frameworks%20out%20there%2C%20it%27s%20infact%20the%20best%20out%20there.%0A%0AAfter%20reading%20a%20lot%20of%20noise%20from%20fellow%20ThoughtWorkers%20in%20the%20recent%20past%20about%20Mockito.%20I%20decided%20to%20give%20a%20yet%20another%20mock%20framework%20a%20try.%0A%0AHere%27s%20what%20I%20ended" rel="nofollow" class="external" title="Add this to DZone">Add this to DZone</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://ketan.padegaonkar.name/2008/03/05/mockito-one-of-the-better-mocks.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
