<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: JAOO - Day 1</title>
	<link>http://www.rubasch.com/2006/10/01/jaoo-day-1/</link>
	<description>Daily Dose of Software Engineering</description>
	<pubDate>Tue, 06 Jan 2009 15:06:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.3</generator>

	<item>
		<title>by: Tammo Freese</title>
		<link>http://www.rubasch.com/2006/10/01/jaoo-day-1/#comment-9</link>
		<pubDate>Sun, 22 Oct 2006 13:10:52 +0000</pubDate>
		<guid>http://www.rubasch.com/2006/10/01/jaoo-day-1/#comment-9</guid>
					<description>Hello Helmut, 

The extra replay() step in EasyMock is there by design, not by requirement.
It would be possible to do implement something like expect(mock).aMethod()
meaning the expect gives back an object which allows the definition of expected method calls for te mock. When I implemented EasyMock 2 last year, I opted against it for two reasons. First, it is harder to read, since the parentheses look misplaced. Second, it is not possible to chain responses, like in expect(mock.aMethod()).andReturn(&quot;avalue&quot;) - and this means that type checking for return values would not work. However, this decision may change in a future version of EasyMock. :)</description>
		<content:encoded><![CDATA[<p>Hello Helmut, </p>
<p>The extra replay() step in EasyMock is there by design, not by requirement.<br />
It would be possible to do implement something like expect(mock).aMethod()<br />
meaning the expect gives back an object which allows the definition of expected method calls for te mock. When I implemented EasyMock 2 last year, I opted against it for two reasons. First, it is harder to read, since the parentheses look misplaced. Second, it is not possible to chain responses, like in expect(mock.aMethod()).andReturn(&#8221;avalue&#8221;) - and this means that type checking for return values would not work. However, this decision may change in a future version of EasyMock. <img src='http://www.rubasch.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Helmut Rubasch</title>
		<link>http://www.rubasch.com/2006/10/01/jaoo-day-1/#comment-8</link>
		<pubDate>Thu, 12 Oct 2006 19:31:53 +0000</pubDate>
		<guid>http://www.rubasch.com/2006/10/01/jaoo-day-1/#comment-8</guid>
					<description>I am quite aware of the advantages of using pure language constructs (that the compiler can check and the IDE can autocomplete) in contrast to pure strings (that are of course not checked in any way during compile time) - in fact, this is one of the main reasons why we are using EasyMock in a project.
Still, some things are rather hard to get used to.
EasyMock's record mechanism is really clever: everything is done at language level, no meta-language (Strings) necessary. Unfortunately this implies, that you need this extra &lt;i&gt;replay&lt;/i&gt; step before you can really use the mock. I don't know how many times I forgot to &lt;i&gt;replay&lt;/i&gt; my mocks - still, you usually find out when trying to break your test, and it just won't break because the mock is still in recording mode (or does &lt;i&gt;mock.verify()&lt;/i&gt; even throw an exception if the mock has not been replayed?).
The ArgumentMatchers are also a very interesting way to accomplish their tasks (unfortunately hard to understand at first, too). Still jMock's Constraints are slightlier more compact to use (no additional static method necessary).
So each, EasyMock and jMock, has some things that it can do a little better or easier than the other. In a perfect world we could take the best from both camps and build some kind of JEasyMock (to be pronounced like &lt;i&gt;CheesyMock&lt;/i&gt;), but the two concepts are just too different for this to work. Even worse, the two base concepts of the two mock libs are in fact &lt;i&gt;the reason&lt;/i&gt; for the shortcomings they have: with EasyMock it just won't be possible to simply provide an ArgumentMatcher to the mock's method call (the compiler would complain), and with jMock you'll never have some more compile time verification. There is just no other way to do these things in their world.
After talking so much about the &quot;problems&quot; of those two mock libs: it's still great to have fabulous tools like these. I could not imagine testing without something like this.</description>
		<content:encoded><![CDATA[<p>I am quite aware of the advantages of using pure language constructs (that the compiler can check and the IDE can autocomplete) in contrast to pure strings (that are of course not checked in any way during compile time) - in fact, this is one of the main reasons why we are using EasyMock in a project.<br />
Still, some things are rather hard to get used to.<br />
EasyMock&#8217;s record mechanism is really clever: everything is done at language level, no meta-language (Strings) necessary. Unfortunately this implies, that you need this extra <i>replay</i> step before you can really use the mock. I don&#8217;t know how many times I forgot to <i>replay</i> my mocks - still, you usually find out when trying to break your test, and it just won&#8217;t break because the mock is still in recording mode (or does <i>mock.verify()</i> even throw an exception if the mock has not been replayed?).<br />
The ArgumentMatchers are also a very interesting way to accomplish their tasks (unfortunately hard to understand at first, too). Still jMock&#8217;s Constraints are slightlier more compact to use (no additional static method necessary).<br />
So each, EasyMock and jMock, has some things that it can do a little better or easier than the other. In a perfect world we could take the best from both camps and build some kind of JEasyMock (to be pronounced like <i>CheesyMock</i>), but the two concepts are just too different for this to work. Even worse, the two base concepts of the two mock libs are in fact <i>the reason</i> for the shortcomings they have: with EasyMock it just won&#8217;t be possible to simply provide an ArgumentMatcher to the mock&#8217;s method call (the compiler would complain), and with jMock you&#8217;ll never have some more compile time verification. There is just no other way to do these things in their world.<br />
After talking so much about the &#8220;problems&#8221; of those two mock libs: it&#8217;s still great to have fabulous tools like these. I could not imagine testing without something like this.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Tammo Freese</title>
		<link>http://www.rubasch.com/2006/10/01/jaoo-day-1/#comment-7</link>
		<pubDate>Thu, 12 Oct 2006 10:03:01 +0000</pubDate>
		<guid>http://www.rubasch.com/2006/10/01/jaoo-day-1/#comment-7</guid>
					<description>&quot;This of course poses a problem when you refactor your classes, but the key point is that your test will fail if you provide an invalid method name (jMock checks if a method with the provided name really exists). So you will find out if you did anything wrong.&quot;

As the author of EasyMock, I also think this is one of the main points, but for another reason: Your tests *pass* first, then you apply a *refactoring*, and then your tests *fail*. So automated refactoring does not work correctly when using jMock mock objects.

Using method calls to define expectations in EasyMock provides more benefits than refactoring safety: Both autocompletion and generation work. 

As an example for autocompletion, consider we have a String stored in the variable login, and an object of type User stored in the variable user. Now we like to check that User mock.someMethod(String) is called with the String stored in login, and we like our mock to return the object stored in the variable person.

jMock:
mock.expects(once()).method(&quot;someMethod&quot;).with( eq(login) ).will(returnValue(person));
EasyMock 2:
expect(mock.someMethod(login)).andReturn(person);

With jMock, autocompletion would not work on someMethod, and the autocompletion for login and person would be cluttered with other completions, as the type is not checked.

With EasyMock, autocompletion would work everywhere, and the autocompletion for login and person would not be cluttered with other completions, as the type is checked, i.e. the autocompletion at 'someMethod(' would only show strings, and the completion at 'andReturn(' would only show user objects.

As an example of code generation, let's say you specify a call to a method which does not exist yet on the mocked interface:

jMock: 
mock.expects(once()).method(&quot;notYetExistingMethod&quot;).with( eq(42) );
EasyMock: 
mock.notYetExistingMethod(42);

With jMock, you have to run your tests to see that the method is missing, and then to define it by hand in the interface. With EasyMock, modern IDEs generate the method automatically for you.</description>
		<content:encoded><![CDATA[<p>&#8220;This of course poses a problem when you refactor your classes, but the key point is that your test will fail if you provide an invalid method name (jMock checks if a method with the provided name really exists). So you will find out if you did anything wrong.&#8221;</p>
<p>As the author of EasyMock, I also think this is one of the main points, but for another reason: Your tests *pass* first, then you apply a *refactoring*, and then your tests *fail*. So automated refactoring does not work correctly when using jMock mock objects.</p>
<p>Using method calls to define expectations in EasyMock provides more benefits than refactoring safety: Both autocompletion and generation work. </p>
<p>As an example for autocompletion, consider we have a String stored in the variable login, and an object of type User stored in the variable user. Now we like to check that User mock.someMethod(String) is called with the String stored in login, and we like our mock to return the object stored in the variable person.</p>
<p>jMock:<br />
mock.expects(once()).method(&#8221;someMethod&#8221;).with( eq(login) ).will(returnValue(person));<br />
EasyMock 2:<br />
expect(mock.someMethod(login)).andReturn(person);</p>
<p>With jMock, autocompletion would not work on someMethod, and the autocompletion for login and person would be cluttered with other completions, as the type is not checked.</p>
<p>With EasyMock, autocompletion would work everywhere, and the autocompletion for login and person would not be cluttered with other completions, as the type is checked, i.e. the autocompletion at &#8217;someMethod(&#8217; would only show strings, and the completion at &#8216;andReturn(&#8217; would only show user objects.</p>
<p>As an example of code generation, let&#8217;s say you specify a call to a method which does not exist yet on the mocked interface:</p>
<p>jMock:<br />
mock.expects(once()).method(&#8221;notYetExistingMethod&#8221;).with( eq(42) );<br />
EasyMock:<br />
mock.notYetExistingMethod(42);</p>
<p>With jMock, you have to run your tests to see that the method is missing, and then to define it by hand in the interface. With EasyMock, modern IDEs generate the method automatically for you.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
