<?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: JMockit: No holds barred testing with instrumentation over mocking</title>
	<atom:link href="http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/feed/" rel="self" type="application/rss+xml" />
	<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/</link>
	<description>Maximum Zeal ~ Emphatic prose on indulged fascinations</description>
	<lastBuildDate>Mon, 08 Mar 2010 06:55:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Creation, dynamic loading and instrumentation with javaagents</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-12225</link>
		<dc:creator>Creation, dynamic loading and instrumentation with javaagents</dc:creator>
		<pubDate>Sun, 07 Feb 2010 22:26:21 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-12225</guid>
		<description>[...] allowed development of powerful non-intrusive tools like JMockit which immediately gains numerous advantages over other mocking tools largely because it is based on instrumentation. I look forward to further [...]</description>
		<content:encoded><![CDATA[<p>[...] allowed development of powerful non-intrusive tools like JMockit which immediately gains numerous advantages over other mocking tools largely because it is based on instrumentation. I look forward to further [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JMockit jar loading from remote file systems enabled</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-12220</link>
		<dc:creator>JMockit jar loading from remote file systems enabled</dc:creator>
		<pubDate>Sun, 07 Feb 2010 13:48:42 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-12220</guid>
		<description>[...] The above changes placed a constraint on classpath ordering and, by default, loaded all tests using the jmockit junit runner rather than the original junit runner and if jmockit wasn&#8217;t properly initialised then all tests would fail as long as jmockit was on the classpath. It&#8217;s a tricky problem to approach for jmockit. Making life easier for certain environments makes it more difficult in others. I would say that jmockit should allow the user to define how they would like their agent loaded and also have jmockit enabled explicitly only and not behind the scenes. Once integrated, however, it is fine mocking library with a unique feature set. [...]</description>
		<content:encoded><![CDATA[<p>[...] The above changes placed a constraint on classpath ordering and, by default, loaded all tests using the jmockit junit runner rather than the original junit runner and if jmockit wasn&#8217;t properly initialised then all tests would fail as long as jmockit was on the classpath. It&#8217;s a tricky problem to approach for jmockit. Making life easier for certain environments makes it more difficult in others. I would say that jmockit should allow the user to define how they would like their agent loaded and also have jmockit enabled explicitly only and not behind the scenes. Once integrated, however, it is fine mocking library with a unique feature set. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhruba Bandopadhyay</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-10561</link>
		<dc:creator>Dhruba Bandopadhyay</dc:creator>
		<pubDate>Wed, 11 Nov 2009 23:42:18 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-10561</guid>
		<description>Rogério what an honour and a pleasure to receive feedback from no other than the JMockit author himself!  I&#039;m new to JMockit but having come across I&#039;ve become fascinated by it.  I&#039;ve made the fixes and enhancements you suggested to the existing example test classes and I&#039;ve also updated the maven pom file so that all tests can be run using maven.  Originally I was running  only in Eclipse one at a time and I presumed that others would do the same but maven ideally should work as well.  The new project download has all these changes.

Given the massive span of JMockit&#039;s feature set this article certainly wasn&#039;t intended to be exhaustive.  My primary goal was to offer the most compelling and fundamental advantages of JMockit over other non-instrumentation based mocking tools to my colleagues both from the point of view of generating interest but also to provoke thought and also naturally to provide examples as a spring board.  I&#039;ll certainly take on board your suggestions for other aspects of JMockit that are interesting and perhaps do another article on them.

Your comments are very gratefully received.  Thanks for stopping by.</description>
		<content:encoded><![CDATA[<p>Rogério what an honour and a pleasure to receive feedback from no other than the JMockit author himself!  I&#8217;m new to JMockit but having come across I&#8217;ve become fascinated by it.  I&#8217;ve made the fixes and enhancements you suggested to the existing example test classes and I&#8217;ve also updated the maven pom file so that all tests can be run using maven.  Originally I was running  only in Eclipse one at a time and I presumed that others would do the same but maven ideally should work as well.  The new project download has all these changes.</p>
<p>Given the massive span of JMockit&#8217;s feature set this article certainly wasn&#8217;t intended to be exhaustive.  My primary goal was to offer the most compelling and fundamental advantages of JMockit over other non-instrumentation based mocking tools to my colleagues both from the point of view of generating interest but also to provoke thought and also naturally to provide examples as a spring board.  I&#8217;ll certainly take on board your suggestions for other aspects of JMockit that are interesting and perhaps do another article on them.</p>
<p>Your comments are very gratefully received.  Thanks for stopping by.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rogério Liesenfeld</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-10557</link>
		<dc:creator>Rogério Liesenfeld</dc:creator>
		<pubDate>Wed, 11 Nov 2009 20:25:32 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-10557</guid>
		<description>I downloaded the Maven project and tried running the tests through the Maven &quot;test&quot; goal.
At first, I got the message that &quot;no tests were found&quot;.

I eventually figured out that Maven only finds test classes whose names end in &quot;Test&quot;, so I renamed them.

With that, Maven finds all test classes and runs them, but fails because neither tools.jar nor &quot;-javaagent:jmockit.jar&quot; was specified. Assuming a JDK 1.6 environment, the best option here is to add the following dependency to the pom.xml:

&lt;pre&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.sun&lt;/groupId&gt;
            &lt;artifactId&gt;tools&lt;/artifactId&gt;
            &lt;version&gt;1.6.0&lt;/version&gt;
            &lt;scope&gt;system&lt;/scope&gt;
            &lt;systemPath&gt;${java.home}/../lib/tools.jar&lt;/systemPath&gt;
        &lt;/dependency&gt;
&lt;/pre&gt;

With this, all tests ran succesfully in my environment. (Remember to remove/change the &quot;skipTests&quot;, though.)</description>
		<content:encoded><![CDATA[<p>I downloaded the Maven project and tried running the tests through the Maven &#8220;test&#8221; goal.<br />
At first, I got the message that &#8220;no tests were found&#8221;.</p>
<p>I eventually figured out that Maven only finds test classes whose names end in &#8220;Test&#8221;, so I renamed them.</p>
<p>With that, Maven finds all test classes and runs them, but fails because neither tools.jar nor &#8220;-javaagent:jmockit.jar&#8221; was specified. Assuming a JDK 1.6 environment, the best option here is to add the following dependency to the pom.xml:</p>
<pre>
        &lt;dependency&gt;
            &lt;groupId&gt;com.sun&lt;/groupId&gt;
            &lt;artifactId&gt;tools&lt;/artifactId&gt;
            &lt;version&gt;1.6.0&lt;/version&gt;
            &lt;scope&gt;system&lt;/scope&gt;
            &lt;systemPath&gt;${java.home}/../lib/tools.jar&lt;/systemPath&gt;
        &lt;/dependency&gt;
</pre>
<p>With this, all tests ran succesfully in my environment. (Remember to remove/change the &#8220;skipTests&#8221;, though.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rogério Liesenfeld</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-10545</link>
		<dc:creator>Rogério Liesenfeld</dc:creator>
		<pubDate>Wed, 11 Nov 2009 02:19:10 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-10545</guid>
		<description>Thanks for the article, it&#039;s very well written!

I spotted a few small mistakes, though:

&lt;ul&gt;
&lt;li&gt;In MockPrivateMethod, an invocation is recorded for User#name(), but later (in the replay phase) the test never calls the method. The test passes because the expected field value was set directly on it, and then read in the &quot;assert&quot;. Instead, the calls to &quot;setField&quot; and &quot;getField&quot; could be removed, with the last line becoming &lt;code&gt;assertEquals(&quot;fred&quot;, Deencapsulation.invoke(user, &quot;name&quot;));&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In MockDefaultConstructor, the Mockit.redefineMethods was used when it should be Mockit.setUpMock or Mockit.setUpMocks (a MockUp class would also do). &quot;redefineMethods&quot; is an older method (Core API) which knows nothing about the @Mock and @MockClass annotations (it could be used in tests written with JDK 1.4 code).&lt;/li&gt;
&lt;li&gt;The same occurs in MockStaticInitialiserBlock. BTW, a nicer way to apply the MockUserInitialiser mock class would be to annotate the test class with &lt;code&gt;@UsingMocksAndStubs(MockUserInitialiser.class)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In VerifyInternalMethods, the &quot;@Mocked&quot; field should be of type User, not UserService. With that, the &lt;code&gt;userService.populateUser();&lt;/code&gt; line inside the verification block should be removed.&lt;/li&gt;
&lt;li&gt;With regard to verification blocks, they are used to verify &lt;em&gt;non-strict&lt;/em&gt; expectations only, which are those recorded inside a NonStrictExpectations block, or belonging to a @NonStrict mocked type, or like in this case when no invocations at all are recorded for the mocked type. All other cases are &lt;em&gt;strict&lt;/em&gt; expectations, which are verified by JMockit implicitly and do not allow &quot;unexpected&quot; invocations.&lt;/li&gt;
&lt;/ul&gt;

There are other insteresting features not mentioned in the article, as well:

&lt;ul&gt;
&lt;li&gt;Local mock fields (declared inside expectation blocks) and mock parameters in test methods.&lt;/li&gt;
&lt;li&gt;Delegate objects passed to the &quot;returns&quot; method.&lt;/li&gt;
&lt;li&gt;Argument matching &lt;em&gt;fields&lt;/em&gt;, which allow you to write &lt;code&gt;user.setAge(anyInt);&lt;/code&gt; instead of &lt;code&gt;user.setAge(withAny(1));&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;@Capturing&lt;/code&gt; annotation, which tells JMockit to mock unspecified implementation classes on demand, as they are loaded by the JVM.&lt;/li&gt;
&lt;/ul&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for the article, it&#8217;s very well written!</p>
<p>I spotted a few small mistakes, though:</p>
<ul>
<li>In MockPrivateMethod, an invocation is recorded for User#name(), but later (in the replay phase) the test never calls the method. The test passes because the expected field value was set directly on it, and then read in the &#8220;assert&#8221;. Instead, the calls to &#8220;setField&#8221; and &#8220;getField&#8221; could be removed, with the last line becoming <code>assertEquals("fred", Deencapsulation.invoke(user, "name"));</code>.</li>
<li>In MockDefaultConstructor, the Mockit.redefineMethods was used when it should be Mockit.setUpMock or Mockit.setUpMocks (a MockUp class would also do). &#8220;redefineMethods&#8221; is an older method (Core API) which knows nothing about the @Mock and @MockClass annotations (it could be used in tests written with JDK 1.4 code).</li>
<li>The same occurs in MockStaticInitialiserBlock. BTW, a nicer way to apply the MockUserInitialiser mock class would be to annotate the test class with <code>@UsingMocksAndStubs(MockUserInitialiser.class)</code>.</li>
<li>In VerifyInternalMethods, the &#8220;@Mocked&#8221; field should be of type User, not UserService. With that, the <code>userService.populateUser();</code> line inside the verification block should be removed.</li>
<li>With regard to verification blocks, they are used to verify <em>non-strict</em> expectations only, which are those recorded inside a NonStrictExpectations block, or belonging to a @NonStrict mocked type, or like in this case when no invocations at all are recorded for the mocked type. All other cases are <em>strict</em> expectations, which are verified by JMockit implicitly and do not allow &#8220;unexpected&#8221; invocations.</li>
</ul>
<p>There are other insteresting features not mentioned in the article, as well:</p>
<ul>
<li>Local mock fields (declared inside expectation blocks) and mock parameters in test methods.</li>
<li>Delegate objects passed to the &#8220;returns&#8221; method.</li>
<li>Argument matching <em>fields</em>, which allow you to write <code>user.setAge(anyInt);</code> instead of <code>user.setAge(withAny(1));</code>.</li>
<li>The <code>@Capturing</code> annotation, which tells JMockit to mock unspecified implementation classes on demand, as they are loaded by the JVM.</li>
</ul>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhruba Bandopadhyay</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-10526</link>
		<dc:creator>Dhruba Bandopadhyay</dc:creator>
		<pubDate>Mon, 09 Nov 2009 23:47:46 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-10526</guid>
		<description>Martin - 10 points. Quote from JMockit:

&lt;blockquote&gt;&quot;The Java compiler does not preserve instance initializers as separate elements in the class file, instead inserting any statements in such blocks into each and every constructor, right after the necessary call to the superclass constructor. Therefore, it is not possible to separately mock instance initialization blocks.&lt;/blockquote&gt;

Of course it&#039;s not a limitation as such because JMockit can mock constructors but it is interesting.</description>
		<content:encoded><![CDATA[<p>Martin &#8211; 10 points. Quote from JMockit:</p>
<blockquote><p>&#8220;The Java compiler does not preserve instance initializers as separate elements in the class file, instead inserting any statements in such blocks into each and every constructor, right after the necessary call to the superclass constructor. Therefore, it is not possible to separately mock instance initialization blocks.</p></blockquote>
<p>Of course it&#8217;s not a limitation as such because JMockit can mock constructors but it is interesting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Harris</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-10525</link>
		<dc:creator>Martin Harris</dc:creator>
		<pubDate>Mon, 09 Nov 2009 23:32:02 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-10525</guid>
		<description>Must be the instance initializer?

int i;
{ i=2;}

Introduced in Java 1.3 for Anonymous classes.  They get inserted into every constructor of the class at runtime.  Its not possible to define a constructor for an Anonymous class but they are given a default constructor.  The static initializer is inserted into that constructor giving you a way to initialize things in Anonymous classes.  I don&#039;t know how it gets from the bytecode, to the constructor at runtime, but I would guess its not part of the actual class as such.  Go on...how does it work?</description>
		<content:encoded><![CDATA[<p>Must be the instance initializer?</p>
<p>int i;<br />
{ i=2;}</p>
<p>Introduced in Java 1.3 for Anonymous classes.  They get inserted into every constructor of the class at runtime.  Its not possible to define a constructor for an Anonymous class but they are given a default constructor.  The static initializer is inserted into that constructor giving you a way to initialize things in Anonymous classes.  I don&#8217;t know how it gets from the bytecode, to the constructor at runtime, but I would guess its not part of the actual class as such.  Go on&#8230;how does it work?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhruba Bandopadhyay</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-10522</link>
		<dc:creator>Dhruba Bandopadhyay</dc:creator>
		<pubDate>Mon, 09 Nov 2009 22:59:15 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-10522</guid>
		<description>Martin - indeed.  In expectations you could throw interrupted exception for produceFilteredFiles and verify that appropriate handling code is called accordingly.  So far the quiz guesses have been synchronisation, serialisation, type erasure and annotations.  All fascinating guesses but not the feature I was thinking of.  A hint would be that it is a little used syntactic feature of a class that helps it initialise its state. Thanks for stopping by.</description>
		<content:encoded><![CDATA[<p>Martin &#8211; indeed.  In expectations you could throw interrupted exception for produceFilteredFiles and verify that appropriate handling code is called accordingly.  So far the quiz guesses have been synchronisation, serialisation, type erasure and annotations.  All fascinating guesses but not the feature I was thinking of.  A hint would be that it is a little used syntactic feature of a class that helps it initialise its state. Thanks for stopping by.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Harris</title>
		<link>http://dhruba.name/2009/11/08/jmockit-no-holds-barred-testing-with-instrumentation-over-mocking/comment-page-1/#comment-10521</link>
		<dc:creator>Martin Harris</dc:creator>
		<pubDate>Mon, 09 Nov 2009 22:45:37 +0000</pubDate>
		<guid isPermaLink="false">http://dhruba.name/?p=1317#comment-10521</guid>
		<description>Looks like it would be handy for testing in multi-threaded situations too...perhaps.  For instance, in the following code its difficult and messy, to test inside the catch for &lt;em&gt;InterruptedException&lt;/em&gt;.  Not sure about your question, but thinking about Type Erasure or perhaps some Annotation issue...need to think harder on that one.

&lt;pre&gt;
    @Override
    public void run() {
        try {
            produceFilteredFiles(this.rootSearchFolder, this.fileProcessor, this.folderFilter);
        } catch (InterruptedException ex) {
            &lt;em&gt;logFailure(LOG, ex);
            Thread.currentThread().interrupt();&lt;/em&gt;
        } finally {
            logExit(LOG);
            filesProducedCdl.countDown();
        }
    }&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Looks like it would be handy for testing in multi-threaded situations too&#8230;perhaps.  For instance, in the following code its difficult and messy, to test inside the catch for <em>InterruptedException</em>.  Not sure about your question, but thinking about Type Erasure or perhaps some Annotation issue&#8230;need to think harder on that one.</p>
<pre>
    @Override
    public void run() {
        try {
            produceFilteredFiles(this.rootSearchFolder, this.fileProcessor, this.folderFilter);
        } catch (InterruptedException ex) {
            <em>logFailure(LOG, ex);
            Thread.currentThread().interrupt();</em>
        } finally {
            logExit(LOG);
            filesProducedCdl.countDown();
        }
    }</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
