<?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>Jimmy&#039;s Blog &#187; jMock</title>
	<atom:link href="http://jimmod.com/blog/tag/jmock/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimmod.com/blog</link>
	<description>My name is Jimmy, and this is my story... ;)</description>
	<lastBuildDate>Wed, 14 Mar 2012 03:19:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using mock object with jmock 2</title>
		<link>http://jimmod.com/blog/2007/12/using-mock-object-with-jmock-2/</link>
		<comments>http://jimmod.com/blog/2007/12/using-mock-object-with-jmock-2/#comments</comments>
		<pubDate>Wed, 26 Dec 2007 11:33:25 +0000</pubDate>
		<dc:creator>jimmy</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[easymock]]></category>
		<category><![CDATA[jMock]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[mock object]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://jimlife.wordpress.com/2007/12/26/using-mock-object-with-jmock-2/</guid>
		<description><![CDATA[ 
				
			 
				
			 
				Tweet 
			
		Okay, finally you decide it&#8217;s time to create a unit testing for your project (after a long ad hoc programming life :p).
When you create a sample unit testing, it&#8217;s all seem so simple.. you fascinate by the junit easiness, how it can do reflection and make it simple.
When you want to [...]


Related posts:<ol><li><a href='http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation For Array Object'>Java ME (J2ME) JSON Implementation For Array Object</a></li><li><a href='http://jimmod.com/blog/2007/12/java-adding-new-classpath-at-runtime/' rel='bookmark' title='Permanent Link: Java &#8211; Adding new Classpath at Runtime'>Java &#8211; Adding new Classpath at Runtime</a></li><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="really_simple_share"><div style="float:left; width:100px; " class="really_simple_share_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjimmod.com%2Fblog%2F2007%2F12%2Fusing-mock-object-with-jmock-2%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="really_simple_share_google1"> 
				<g:plusone size="medium" href="http://jimmod.com/blog/2007/12/using-mock-object-with-jmock-2/" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="really_simple_share_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="none" 
					data-text="Using mock object with jmock 2" data-url="http://jimmod.com/blog/2007/12/using-mock-object-with-jmock-2/">Tweet</a> 
			</div></div>
		<div style="clear:both;"></div><p>Okay, finally you decide it&#8217;s time to create a unit testing for your project (after a long ad hoc programming life :p).<br />
When you create a sample unit testing, it&#8217;s all seem so simple.. you fascinate by the junit easiness, how it can do reflection and make it simple.</p>
<p>When you want to create a real unit testing for your project, you realize that a &#8216;real&#8217; method is not like just adding 2 int argument and return a result. It&#8217;s more complex and using interface as parameter is common&#8230;<br />
Now a thought cross your mind &#8220;do I have to create all stupid classes to implement all the interface I need?&#8221;, you starting to think that creating unit testing is really waste of time &amp; you don&#8217;t want to do it anymore :p</p>
<p>It&#8217;s time mock object framework come to rescue&#8230; before you fall to the darkness of untested code <img src='http://jimmod.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
There&#8217;re several mock object framework like <a href="http://www.jmock.org/download.html" title="jMock">jMock</a>, <a href="http://www.easymock.org/" title="easymock">easymock</a>, etc</p>
<p>Here&#8217;s an example creatin HttpMethod mock-object with jMock 2 &amp; JUnit 3</p>
<p>[sourcecode language='java']<br />
public class sampleJMockTest extends MockObjectTestCase {<br />
  public void testCreateHTTPMethod() {<br />
    final HttpMethod httpMethod = mock(HttpMethod.class);<br />
    checking(new Expectations() {<br />
    {<br />
      allowing(httpMethod).getResponseBodyAsString();<br />
      will(returnValue(&#8221;sample response&#8221;));<br />
    }<br />
    });<br />
    SomeObject someObject = new SomeObject();<br />
    someObject.someMethod(httpMethod);<br />
  }<br />
}[/sourcecode]<br />
This sample will create an instance of HttpMethod (which is an interface) and when this mock object&#8217;s &#8216;getResponseBodyAsString&#8217; method called it&#8217;ll return &#8220;sample response&#8221;.<br />
So now we can easily create all interface implementation we need.Of course there&#8217;re more in jMock than just this simple feature, check it more at <a href="http://www.jmock.org/cookbook.html" title="jMock Cookbook">jMock Cookbook</a></p>


<p>Related posts:<ol><li><a href='http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation For Array Object'>Java ME (J2ME) JSON Implementation For Array Object</a></li><li><a href='http://jimmod.com/blog/2007/12/java-adding-new-classpath-at-runtime/' rel='bookmark' title='Permanent Link: Java &#8211; Adding new Classpath at Runtime'>Java &#8211; Adding new Classpath at Runtime</a></li><li><a href='http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/' rel='bookmark' title='Permanent Link: Java ME (J2ME) JSON Implementation Tutorial/Sample'>Java ME (J2ME) JSON Implementation Tutorial/Sample</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://jimmod.com/blog/2007/12/using-mock-object-with-jmock-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

