<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>Tools @ clintshank.javadevelopersjournal.com</title><link>http://clintshank.javadevelopersjournal.com/</link><description>(Tools) My thoughts on software development.</description><copyright>Copyright 2008 clintshank.javadevelopersjournal.com</copyright><generator></generator><lastBuildDate>Fri, 05 Sep 2008 17:00:00 GMT</lastBuildDate><image><title>Tools @ clintshank.javadevelopersjournal.com</title><url>http://res.sys-con.com/portlet/163/featured-blog-graphic-145.gif</url><link>http://clintshank.javadevelopersjournal.com/</link></image><ttl>360</ttl><docs>http://backend.userland.com/rss</docs><item><title>Hudson CI Game Plugin</title><guid isPermaLink="true">http://clintshank.javadevelopersjournal.com/hudson_ci_game_plugin.htm</guid><link>http://clintshank.javadevelopersjournal.com/hudson_ci_game_plugin.htm</link><pubDate>Thu, 17 Apr 2008 22:50:00 GMT</pubDate><comments>http://clintshank.javadevelopersjournal.com/console/comments/popup/?f=hudson%5Fci%5Fgame%5Fplugin</comments><dc:creator>Clint Shank</dc:creator><description><![CDATA[<p><a href="http://redsolo.blogspot.com/">redsolo</a>  has implemented a version of <a href="/ci_build_game.htm">The Continuous Integration Build Game</a>.&nbsp; It&#39;s a <a href="https://hudson.dev.java.net/">Hudson</a>  plugin and is described <a href="http://redsolo.blogspot.com/2008/04/start-playing-continuous-integration.html">here</a> .&nbsp; Way to go redsolo!<br /> </p>]]></description><category>build</category><category>ci</category><category>tools</category></item><item><title>Parallel JUnit Ant Task</title><guid isPermaLink="true">http://clintshank.javadevelopersjournal.com/parallel_junit_ant_task.htm</guid><link>http://clintshank.javadevelopersjournal.com/parallel_junit_ant_task.htm</link><pubDate>Tue, 16 Oct 2007 15:41:00 GMT</pubDate><comments>http://clintshank.javadevelopersjournal.com/console/comments/popup/?f=parallel%5Fjunit%5Fant%5Ftask</comments><dc:creator>Clint Shank</dc:creator><description><![CDATA[<p>Over time, how do you maintain a maximum <a href="http://www.think-box.co.uk/blog/2006/02/ten-minute-build-continuous.html">10 minute build</a>? This is an important agile practice for <a href="http://en.wikipedia.org/wiki/Continuous_integration">continuous integration</a>.</p><p>It&#39;s inevitable. As more and more features are added to an application, the code base grows. The build has more to do: more compiling, more tests and metrics to run, more reports to generate. We&#39;ve done numerous things to keep the build time down. In this entry, I&#39;d like to describe one of them: running standard JUnit tests concurrently.</p><p>A colleague of mine came up with this idea.&nbsp;He first did a preliminary search to see if anything already existed.&nbsp; Pretty much everything he found was intrusive, e.g., requiring extending a specialized TestCase.&nbsp; He then&nbsp;attempted&nbsp;to combine <a href="http://ant.apache.org/manual/index.html">Ant&#39;s Parallel and JUnit tasks</a>. That is, he could simply nest N number of JUnit tasks inside a Parallel task. The problem here was coming up with a good way to divide the tests up into equal parts beforehand. My colleague quickly scrapped this idea in favor of a custom Ant task that wrapped the JUnit task.</p><p>The thought was to leverage the JUnit task as much as possible, but fronting it with the ability to run tests in parallel. The conceptual design looks like this:</p><p><img src="http://files.blog-city.com/files/J06/154001/p/f/paralleljunit.png" alt="Conceptual design" width="314" height="74" /></p><p>There are N number of TestExecutors. A TestExecutor runs in a single JVM. Thus, there are N JVMs. Say we have a dedicated, 4 processor integration machine running builds. We may choose to configure our custom task with 5 TestExecutors (we&#39;ll add one&nbsp;assuming&nbsp;we&#39;re not 100% compute bound). Note: if you&#39;re familiar with the JUnit task, you may be wondering how its fork/forkmode attributes fit in. The answer is that they are&nbsp;eliminated in favor of this jvm-count attribute.</p><p>There&#39;s a single TestProvider. His job is to gather all the tests and hand them out one at a time to whichever TestExecutor is ready. A simple protocol exists to let a TestExecutor tell the TestProvider that he&#39;s done and ready for another test.&nbsp; This should maximize parallelism.</p><p>The biggest negative with this approach is that since all tests run in a fixed number of JVMs,&nbsp;there&#39;s some loss of isolation here. Class level/global state set from a previous test could affect later tests. We&#39;re willing to trade this for increased performance.</p><p>The other possible downside is the use of a non-standard Ant task.</p><p>Using this approach&nbsp;we&#39;ve successfully reduced our build time to usable levels.</p><p>&nbsp;</p>]]></description><category>testing</category><category>tools</category><category>build</category><category>ci</category></item><item><title>Bad PMD Rules</title><guid isPermaLink="true">http://clintshank.javadevelopersjournal.com/bad_pmd_rules.htm</guid><link>http://clintshank.javadevelopersjournal.com/bad_pmd_rules.htm</link><pubDate>Fri, 09 Mar 2007 05:00:00 GMT</pubDate><comments>http://clintshank.javadevelopersjournal.com/console/comments/popup/?f=bad%5Fpmd%5Frules</comments><dc:creator>Clint Shank</dc:creator><description><![CDATA[<p><a href="http://pmd.sourceforge.net/">PMD</a>  is an excellent tool for finding potential bugs and improving code quality, but it can generate a lot of false positives.  Here&#39;s my list of the top 10 rules I turn off immediately, in alphabetical order, with a short comment explaining why.  Descriptions for the rules can be found <a href="http://pmd.sourceforge.net/rules/index.html">here</a>.</p><ol><li><strong>AtLeastOneConstructor</strong>: Why?  Code is smaller without an empty, no-args contructor.</li><li><strong>AvoidInstantiatingObjectsInLoops</strong>:  This one just seems to generate too many false positives.  In addition, for short-lived objects, garbage collection is essentially free.</li><li><strong>CallSuperInConstructor</strong>: super() is called implicitly and requiring it just adds more lines of code.</li><li><strong>JUnitAssertionsShouldIncludeMessage</strong>: Most of the methods in Assert already generate good messages.  I do include a message for those that don&#39;t (assertTrue(), assertFalse(), fail()).</li><li><strong>LocalVariableCouldBeFinal</strong>:  final for variables is usually overkill and it adds line length.</li><li><strong>LongVariable</strong>: Clarity rules! </li><li><strong>MethodArgumentCouldBeFinal</strong>: Same as LocalVariableCouldBeFinal.</li><li><strong>OnlyOneReturn</strong>: I think it&#39;s clearer to exit early.  It reduces the amount of things to think about below the exit.</li><li><strong>PositionLiteralsFirstInComparisons</strong>: This really isn&#39;t that bad, but myString.equals(&quot;x&quot;) just reads better than &quot;x&quot;.equals(myString).</li><li><strong>ShortVariable</strong>:  There are just too many cases where it&#39;s acceptable to have short variables in <a href="/smallmethods.htm">small methods</a> .</li></ol><p>&nbsp;These two just missed the cut:</p><ul><li><strong>ShortMethodName</strong>: I try to make my names expressive.  I&#39;ve never seen this rule fire. </li><li><strong>SignatureDeclareThrowsException</strong>:  This is an okay rule, but for JUnit tests, who cares?</li></ul><p>&nbsp;</p><p>&nbsp;</p>]]></description><category>tools</category></item><item><title>Behavior Driven Development with JUnit 4</title><guid isPermaLink="true">http://clintshank.javadevelopersjournal.com/bdd_junit4.htm</guid><link>http://clintshank.javadevelopersjournal.com/bdd_junit4.htm</link><pubDate>Thu, 14 Dec 2006 22:54:00 GMT</pubDate><comments>http://clintshank.javadevelopersjournal.com/console/comments/popup/?f=bdd%5Fjunit4</comments><dc:creator>Clint Shank</dc:creator><description><![CDATA[<p>JUnit 4 makes <a href="http://en.wikipedia.org/wiki/Behavior_driven_development">Behavior Driven Development (BDD)</a>  style testing (or specification) easier.</p><p>Let&#39;s quickly look at an example, the idea stolen from one of <a href="http://www.butunclebob.com/ArticleS.DavidChelimsky.SpecOrganization">David Chelimsky&#39;s blog entries</a>  about specifying the behavior of a stack.  We&#39;re focused here on the specification of an empty stack:</p><pre>// notice the class name specifies the context<br />public class EmptyStack {<p>    private Stack stack = null;<br />    <br />    @Before<br />    public void setUp() {<br />        // set up the context<br />        stack = new Stack();<br />    }</p><p>    <br />    // notice the name focuses on the context<br />    @Test<br />    public void shouldBeEmpty() {<br />        assertTrue(&quot;not empty&quot;, stack.isEmpty());<br />    }</p><p>    <br />    @Test(expected=EmptyStackException.class)<br />    public void shouldComplainOnPeek() {<br />        stack.peek();<br />    }<br />    <br />    <br />    // more specification focused methods<br />}</p></pre><p>The point here is that you can get many of the benefits of BDD (a focus on specification rather than testing) using the familiar JUnit framework.</p><p>Now, if you&#39;re a hardcore BDD&#39;er, then you might complain that you still have to use a test-centric vocabulary.  You still need those Test annotations and method calls like assertEquals rather than <a href="http://www.daveastels.com/">Dave Astels&#39;</a>  preferred shouldEquals calls.</p><p>Also, from the legacy side of the fence, you lose the convention of method names starting with testSomething and class names ending with Test.  It&#39;s sometimes hard to let go of that if you&#39;ve been writing tests for a long time and it&#39;s super clear to spot those test methods and test classes if you&#39;re following a naming convention.  Furthermore, Ruby on Rails has taught us that convention is a good thing.  The test method naming convention doesn&#39;t really bother me so much.  The @Test annotation makes things clear enough and shouldSomething really gets us focused on specification.  However, I haven&#39;t let go of ending the class name with Test.  Maybe it&#39;s more because Ant can pick those tests up easier if there&#39;s a standard naming convention.</p><p>The last negative I can think of is that of consistency.  Having a mix of old style test centric tests and BDD style tests could bother some.</p><p>So, let&#39;s be honest.  What am I really doing?  Well, I am incorporating more and more BDD into my work.  However, I still shy away from creating new classes.  The BDD style really lends itself to many test classes (contexts) per class under test.  In the case of Stack, as David Chelimsky points out, you&#39;d also need AlmostEmptyStack, AlmostFullStack, and FullStack classes to fully specify the behavior.  I just can&#39;t commit myself to writing all those.  But I am focusing more on the set up of a context and the specification methods of that context.  I just may cheat a little and combine contexts into a single class.  So perhaps in the Stack example, I&#39;d combine the empty and almost empty stack contexts under one test class.  You know, I&#39;d set up an empty Stack in setUp and for the almost empty context, I&#39;d do a little more set up (push something) in the appropriate shouldSomething methods to make it almost empty.</p><p>I also revert back to legacy style testing sometimes.  This is usually when I&#39;m modifying an existing, old style test.  It&#39;s just simpler and faster, and typically the context isn&#39;t set up too well for the BDD style.</p><p>So my advice is to use the right tool for the job.  Use BDD style when that makes things clearer and you want to focus on specification.  Use test centric style when that&#39;s easier.  Try to do a better job of focusing more on specification and less on verification, especially when you&#39;re adding new behavior.</p><p>&nbsp;</p>]]></description></item><item><title>A Common Set of Test Refactorings</title><guid isPermaLink="true">http://clintshank.javadevelopersjournal.com/commontestrefactorings.htm</guid><link>http://clintshank.javadevelopersjournal.com/commontestrefactorings.htm</link><pubDate>Sun, 19 Feb 2006 13:02:00 GMT</pubDate><comments>http://clintshank.javadevelopersjournal.com/console/comments/popup/?f=commontestrefactorings</comments><dc:creator>Clint Shank</dc:creator><description><![CDATA[Today, I want to blog about what I think might be my most common set of low level Eclipse refactorings used together when I&rsquo;m developing unit tests.&nbsp;I use this set to parameterize tests as discussed in <a href="http://clintshank.javadevelopersjournal.com/tabulartests.htm">Tabular Tests</a>.&nbsp;Lately, I&rsquo;ve been trying to use the Eclipse refactorings as much as possible, thinking that the automation would be less likely to break things than if I made the changes manually.&nbsp;It&rsquo;s also interesting to make code changes without doing any typing.&nbsp;The set consists of:
<ol type="1" style="margin-top: 0in;" start="1">
    <li><font face="Courier New">Extract      Local Variable</font> (possibly multiple times).</li>
    <li><font face="Courier New">Extract      Method</font></li>
    <li><font face="Courier New">Inline</font>      the local variables created in step 1.</li>
</ol>
So let&rsquo;s suppose I&rsquo;m about to start work on a new method.&nbsp;I like to start with a brain dump of most, if not all of the test cases.&nbsp;This is to get me thinking about the desired behavior and also because it clears my head, so that when I start writing the code, I can focus.&nbsp;Once I&rsquo;m ready, I start with a simple case.
<p>Let&rsquo;s take the <font face="Courier New">Range.equals()</font> example from the previous blog.&nbsp;My brain dump would have resulted in a table like this:</p>
<p>
<table width="200" cellspacing="1" cellpadding="1" border="1" align="">
    <tbody>
        <tr>
            <td><strong>Min</strong></td>
            <td><strong>Max</strong></td>
            <td><strong>Equals?</strong></td>
        </tr>
        <tr>
            <td>same</td>
            <td>same</td>
            <td>true</td>
        </tr>
        <tr>
            <td>different</td>
            <td>same</td>
            <td>false</td>
        </tr>
        <tr>
            <td>same</td>
            <td>different</td>
            <td>false</td>
        </tr>
    </tbody>
</table>
</p>
<p>Yes, I would have jotted down other, exceptional cases for things like <font face="Courier New">null</font> and a non-<font face="Courier New">Range</font> object, but that&rsquo;s out of scope here.&nbsp;For this blog, I&rsquo;m just concentrated on comparing <font face="Courier New">Range</font> objects.&nbsp;I start with the positive case and come up with something like:</p>
<p><code><span style="font-size: 10pt;">&nbsp;&nbsp; private static final int MIN = 1;<br /> &nbsp;&nbsp; private static final int MAX = 7;<br /> <br /> &nbsp;&nbsp; private Range range = new Range(MIN, MAX);</span></code> </p>
<div><code>&nbsp;</code></div>
<code><span style="font-size: 10pt;">&nbsp; &nbsp;public void testEqualsAnotherRange() {<br /> &nbsp; &nbsp; &nbsp; Range anotherRange = new Range(MIN, MAX);<br /> &nbsp; &nbsp; &nbsp; assertEquals(range, anotherRange);<br /> &nbsp; &nbsp;}</span></code>
<p>&nbsp;</p>
<p><code><span style="font-size: 10pt;"> </span></code>To be honest, I probably would have had the <font face="Courier New">MIN</font> and <font face="Courier New">MAX</font> constants hardcoded in there, but at some point, I would have performed <font face="Courier New">Extract Constant</font> to come up with the above.</p>
<p>After I get that test to pass (by returning <font face="Courier New">true</font>), I&rsquo;m ready to write the next test.&nbsp;I want to pick something simple again (of course in this example they&rsquo;re all simple).&nbsp;But before I write the next test, I do something that is probably considered cheating by the hardcore test-driven development crowd.&nbsp;I&rsquo;m not too concerned because I know from experience that I&rsquo;m going to end up with tabular tests.&nbsp;In fact, the table is specified above! &nbsp;So here goes the set of refactorings:</p>
<p>I first <font face="Courier New">Extract Local Variable</font> on <font face="Courier New">MIN</font> and <font face="Courier New">MAX</font>:</p>
<p><code><span style="font-size: 10pt;">&nbsp; &nbsp;public void testEqualsAnotherRange() {<br /> &nbsp; &nbsp; &nbsp; <strong>int testMin = MIN;<br /> &nbsp; &nbsp; &nbsp; int testMax = MAX;</strong><br /> &nbsp; &nbsp; &nbsp; Range anotherRange = new Range(<strong>testMin, testMax</strong>);<br /> &nbsp; &nbsp; &nbsp; assertEquals(range, anotherRange);<br /> &nbsp; &nbsp;}</span></code></p>
<p><code><span style="font-size: 10pt;"></span></code><span style=""><br /> </span>Now I know from my table that I need a <font face="Courier New">boolean</font> for my expected equals. There's no simple Eclipse refactoring so I manually make the change: </p>
<p><code><span style="font-size: 10pt;">&nbsp;&nbsp; public void testEqualsAnotherRange() {<br /> &nbsp; &nbsp; &nbsp; int testMin = MIN;<br /> &nbsp; &nbsp; &nbsp; int testMax = MAX;<br /> &nbsp; &nbsp; &nbsp; <strong>boolean expectedEquals = true;</strong><br /> &nbsp; &nbsp; &nbsp; Range anotherRange = new Range(testMin, testMax);<br /> &nbsp; &nbsp; &nbsp; <strong>assertEquals(expectedEquals, range.equals(anotherRange));</strong><br /> &nbsp; &nbsp;}</span></code></p>
<p><code><span style="font-size: 10pt;"></span></code><span style=""><br /> </span>I highlight the last two lines and perform <font face="Courier New">Extract Method</font>:<br /><br /> <code><span style="font-size: 10pt;">&nbsp; &nbsp;public void testEqualsAnotherRange() {<br /> &nbsp; &nbsp; &nbsp; &nbsp;int testMin = MIN;<br /> &nbsp; &nbsp; &nbsp; &nbsp;int testMax = MAX;<br /> &nbsp; &nbsp; &nbsp; &nbsp;boolean expectedEquals = true;<br /> &nbsp; &nbsp; &nbsp; &nbsp;<strong>testEqualsAnotherRange(testMin, testMax, expectedEquals);</strong><br /> &nbsp; &nbsp;}<br /> <br /><strong> &nbsp; &nbsp;private void testEqualsAnotherRange(int testMin, int testMax,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boolean expectedEquals) {<br /> &nbsp; &nbsp; &nbsp; &nbsp;Range anotherRange = new Range(testMin, testMax);<br /> &nbsp; &nbsp; &nbsp; &nbsp;assertEquals(expectedEquals, range.equals(anotherRange));<br /> &nbsp; &nbsp;}</strong></span></code></p>
<p><code><span style="font-size: 10pt;"></span></code><span style=""><br /> </span>I want to get back to what it looks like in the table, so I <font face="Courier New">Inline</font> each local variable:</p>
<p><code><span style="font-size: 10pt;">&nbsp;&nbsp; public void testEqualsAnotherRange() {<br />&nbsp; &nbsp; &nbsp; testEqualsAnotherRange(<strong>MIN, MAX, true</strong>);<br /> &nbsp; &nbsp;}<br /> <br /> &nbsp; &nbsp;private void testEqualsAnotherRange(int testMin, int testMax,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boolean expectedEquals) {<br /> &nbsp; &nbsp; &nbsp; Range anotherRange = new Range(testMin, testMax);<br /> &nbsp; &nbsp; &nbsp; assertEquals(expectedEquals, range.equals(anotherRange));<br /> &nbsp; &nbsp;}</span></code></p>
<p><code><span style="font-size: 10pt;"></span></code><span style=""><br /> </span>I just created the first row of the table by applying the set of refactorings that is the topic of this blog.&nbsp;At this point, I usually look at the parameterized method and make sure I&rsquo;m happy with the signature.&nbsp;I&rsquo;ve already done most of this when I extracted the method, but Eclipse doesn&rsquo;t let me make the method <font face="Courier New">static</font>, if that&rsquo;s appropriate (in this case it&rsquo;s not).&nbsp;Eclipse also lists all the checked exceptions, which for tests, I&rsquo;d rather generalize to <font face="Courier New">Exception</font>.&nbsp; This doesn't apply in this case either.<br /></p>
<p>During this set of refactorings, I would have ran the tests after a change or two just to make sure I didn&rsquo;t break anything.&nbsp;I also do that because it feels good to get that green bar.</p>
<p>This is a pretty trivial example.&nbsp;Most of the time much more is going on in the parameterized method, but this still shows the removal of duplication.</p>
<p>I could have made these changes manually, but like I mentioned above, I like the automation; I&rsquo;m less likely to break things.</p>
<div>Okay, I can write the next test now:</div>
<p><code><span style="font-size: 10pt;">&nbsp;&nbsp; public void testEqualsAnotherRange() {<br /> &nbsp; &nbsp; &nbsp; testEqualsAnotherRange(MIN, &nbsp; &nbsp; MAX, true);<br /> &nbsp; &nbsp; &nbsp; <strong>testEqualsAnotherRange(MIN - 1, MAX, false);</strong><br /> &nbsp; &nbsp;}</span></code></p>
<p><code><span style="font-size: 10pt;"> </span></code>I&rsquo;ve got the red bar.&nbsp;Time to make it green.</p>
<div>&nbsp;</div>]]></description></item></channel></rss>