<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Conversations with Dale]]></title>
  <link href="http://cwd.dhemery.com/atom.xml" rel="self"/>
  <link href="http://cwd.dhemery.com/"/>
  <updated>2012-01-02T17:57:07-08:00</updated>
  <id>http://cwd.dhemery.com/</id>
  <author>
    <name><![CDATA[Dale Emery]]></name>
    <email><![CDATA[dale@dhemery.com]]></email>
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Towers Episode 1: The Reclining Ribcage]]></title>
    <link href="http://cwd.dhemery.com/2011/01/ribcage/"/>
    <updated>2011-01-18T15:26:28-08:00</updated>
    <id>http://cwd.dhemery.com/2011/01/ribcage</id>
    <content type="html"><![CDATA[<p>As we begin this episode, I’ve just created <a href="https://github.com/dhemery/Towers/commit/252be5b80247ba67f5e04a25ad5ac4b88c0c059a">a fresh repository</a>, and I’m ready to start developing my Towers game.</p>




<h3>The Walking Skeleton</h3>




<p>I pick what I think will be a good “walking skeleton” feature, a feature chosen specifically to quickly conjure much of the application structure into existence. I choose this feature: <em>On launch, Towers displays an 8 block x 8 block “city” of black and white towers, each one floor high, arranged in a checkerboard pattern.</em></p>




<p>With this feature in mind, I write the first acceptance test.</p>




<h3>The City is Eight Blocks Square</h3>




<p><strong>Acceptance test: <em><a href="https://github.com/dhemery/Towers/blob/7bf3a0496709373f5724e2b7a7dfebdf45b17698/test/acceptance/com/dhemery/towers/application/OnLaunch.java">The city is eight blocks square.</a></em></strong> I try to make the test very expressive, using a “fluent” style of assertions. To support the test, I write a <code><a href="https://github.com/dhemery/Towers/blob/057d4dec5bbce846f2cb666fbd40fda92812c2b6/test/acceptance/com/dhemery/towers/application/fixtures/CityFixture.java">CityFixture</a></code> class to access information about the city through the GUI, and a <code><a href="https://github.com/dhemery/Towers/blob/057d4dec5bbce846f2cb666fbd40fda92812c2b6/test/acceptance/com/dhemery/towers/application/fixtures/CityAssertion.java">CityAssertion</a></code> class to build the fluent assertion DSL. (This may seem overly complex to you. Hold that thought.)</p>




<p>For assertions I use the <a href="http://docs.codehaus.org/display/FEST/Fluent+Assertions+Module">FEST Fluent Assertions Module</a>. I like the fluent style assertions. In particular, I like being able to type a dot after <code>assertThat(someObject)</code>, and having Eclipse pop up a list of things I can assert about the object.</p>




<p>To sense and wiggle stuff through the GUI, I use the <a href="http://docs.codehaus.org/display/FEST/Swing+Module">FEST Swing Module</a>.</p>




<p><strong>Implementation.</strong> To pass this test, I write code directly into <code><a href="https://github.com/dhemery/Towers/blob/7bf3a0496709373f5724e2b7a7dfebdf45b17698/src/com/dhemery/towers/application/Towers.java">Towers</a></code>, the application’s main class.</p>




<p>At this point, Towers has a display (an empty JFrame), which is prepared to display 64 somethings in an 8 x 8 grid. But it doesn’t yet display any somethings. It’s an 8 x 8 ghost city.</p>




<h3>Each City Block Has a One Floor Tower</h3>




<p><strong>Acceptance test: <em><a href="https://github.com/dhemery/Towers/blob/ec08ffa0727c1fd314fed881fd1086e8d63227bd/test/acceptance/com/dhemery/towers/application/OnLaunch.java">Each city block has a one floor tower</a>.</em></strong> To extend the test DSL, I add <code><a href="https://github.com/dhemery/Towers/blob/ec08ffa0727c1fd314fed881fd1086e8d63227bd/test/acceptance/com/dhemery/towers/application/fixtures/TowerFixture.java">TowerFixture</a></code> and <code><a href="https://github.com/dhemery/Towers/blob/ec08ffa0727c1fd314fed881fd1086e8d63227bd/test/acceptance/com/dhemery/towers/application/fixtures/TowerAssertion.java">TowerAssertion</a></code> classes. (This DSL stuff may now seem even more complex to you. Hold that thought.)</p>




<p><strong>Implementation.</strong> I make <a href="https://github.com/dhemery/Towers/blob/ec08ffa0727c1fd314fed881fd1086e8d63227bd/src/com/dhemery/towers/application/Towers.java">the main class</a> display a JButton to represent a tower at each grid location. Grid location seems like a coherent, meaningful concept, so I test-drive a class to represent that. I quickly find that I care only about the location’s name, so I name the class <code><a href="https://github.com/dhemery/Towers/blob/ec08ffa0727c1fd314fed881fd1086e8d63227bd/src/com/dhemery/towers/model/Address.java">Address</a></code>. I name each button based on its address, to allow the test fixtures to look up each “tower” by name. Each button displays “1” to represent the height of the tower.</p>




<p>At this point, there is no model code beyond Address. A tower is represented only by the text displayed in a button.</p>




<p><strong>Speculation.</strong> To pass this test I could have used a simple JLabel to display the tower height. My choice of the more complex JButton was entirely speculative. That was very naughty.</p>




<p><strong>More speculation.</strong> I notice that there’s an orphan <code><a href="https://github.com/dhemery/Towers/blob/ec08ffa0727c1fd314fed881fd1086e8d63227bd/src/com/dhemery/towers/model/Tower.java">Tower</a></code> class sitting all alone in the corner of the repo. Though I’m trying to code outside-in here, my natural bias toward coding inside-out must have asserted itself. The class isn’t actually used in my app, which suggests that I wrote it on speculation. It’s interesting that I would do that. I wonder: Is all inside-out coding speculative?</p>




<p><strong>Blind speculation.</strong> I didn’t commit a test for the unused <code>Tower</code> class. I&#8217;m sure that means I didn&#8217;t write one. So I must have coded it not only speculatively, but blindly. Eeep!</p>




<p><strong>Repospectives.</strong> As I step through the commit chain, I see my sins laid out before me. If Saint Peter uses git, I&#8217;m fucked. But I wonder: What else might we learn by stepping through our own git repositories?</p>




<h3>Towers Alternate Colors</h3>




<p><strong>Acceptance Test: <em><a href="https://github.com/dhemery/Towers/blob/master/test/acceptance/com/dhemery/towers/application/OnLaunch.java">Towers alternate colors</a>.</em></strong> I express this by checking that towers alternate colors down the first column, and that towers alternate colors along each row.</p>




<p><strong>Simplifying the fixtures.</strong> As I write the third test and the fixture code to support it, I become weary of maintaining and extending my lovely DSL. I abandon it in favor of writing indicative mood statements in simpler <code>&lt;object&gt;.&lt;condition&gt;()</code> format. Now I need only one fixture class per domain concept, rather than two (a class to access items through the GUI and class to make assertions).</p>




<p>Though “the city has width eight” doesn’t trip off the tongue as nicely as “the city is eight blocks wide,” it conveys nearly the same information. The only loss is the idea of “blocks.” I’m okay with that.</p>




<p><strong>Implementation.</strong> I make the main class render each button with foreground and background colors based on the button’s location in the grid.</p>




<p><strong>Adding features to the main class.</strong> At this early point in the project I’m implementing features mostly by writing code directly in the main class. I’m nervous about this, but I’m doing it on purpose, deliberately following the style Steve Freeman and Nat Pryce illustrate in <em><a href="http://www.amazon.com/exec/obidos/ASIN/0321503627/dalehemery-20">Growing Object-Oriented Software, Guided by Tests</a></em> (GOOS). For early features, they write the code in the main class. Later, as the code begins to take shape, they notice the coherent concepts emerging in the code, and extract classes to represent those.</p>




<p>When I first read that, I was surprised. My style is to ask, before writing even the smallest chunk of code: To what class will I allocate this responsibility? Then I test-drive that class. Steve and Nat’s style felt wrong somehow. I made note of that.</p>




<p>Around the same time that I first read GOOS, I watched <a href="http://pragprog.com/screencasts/v-kbtdd/test-driven-development">Kent Beck’s illuminating video series about TDD</a>. In those videos, Kent often commented that he was leaving some slight awkwardness in the code until he had a better idea became apparent (I’m paraphrasing from memory here, perhaps egregiously).</p>




<p>So once again a pattern emerges: Someone really smart says something clearly nonsensical. I think, “That makes no sense,” and let it go. Then someone else really smart says something similar. I think, “How the hell does that work?” Eventually, when enough really smart people have said the same stupid thing, I think, “That makes no sense. I’d better try it.” Then I try it, and it makes sense. Immediately thereafter I wonder why it isn’t obvious to everyone.</p>




<p>As I’ve mentioned, my bias is to code inside-out, writing model code first, then connecting it to the outside world. Now aware of my bias, I chose to work against it. I wrote the code directly into the main class. I was still nervous about that. But I’m still alive, so I must have survived it.</p>




<p><strong>Commit.</strong> The first feature finally fully functions. As I commit this code, a tower is still represented only by the color, text, and name of a button. The only model class is <code>Address</code>, a value class with a name tag.</p>




<p>This will change in the next episode when, within seconds of committing this code, I somewhat appease my I MUST ALWAYS ADD CODE IN THE RIGHT PLACE fetish by immediately extracting a new class.</p>




<h3>That Skeleton Won’t Walk</h3>




<p>There’s a problem here. Though I’ve implemented the entire walking skeleton feature, and the implementation brings major chunks of the user interface into existence, the feature does not yet compel the system to respond to any events. It therefore does not require the system to do anything or decide anything in response to external events.</p>




<p>In retrospect, I chose a poor candidate for a walking skeleton. For one thing, it doesn’t walk. It just sort of reclines. For another, it’s not a whole skeleton. At best it&#8217;s a ribcage. A reclining ribcage. So there’s a lesson for me to learn: <em>Choose a walking skeleton that responds to external events.</em></p>




<p>As I wrote this blog post, I searched the web for a definition of “walking skeleton.” Alistair Cockburn <a href="http://alistair.cockburn.us/Walking+skeleton">defines a walking skeleton</a> as “a tiny implementation of the system that performs a small end-to-end function.” If I’d looked that up earlier (or if I&#8217;d remembered the definition from when I first saw it years ago), I would likely have chosen a different feature to animate this corpse. Likely something about moving one tower onto another.</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Towers Prologue: GOOS, The Itch, Blunt Instruments, and The Thing]]></title>
    <link href="http://cwd.dhemery.com/2011/01/thing/"/>
    <updated>2011-01-18T03:38:39-08:00</updated>
    <id>http://cwd.dhemery.com/2011/01/thing</id>
    <content type="html"><![CDATA[<p><strong>Towers.</strong> Last year I developed Towers [<a href="http://dhemery.com/pdf/towers.pdf">PDF</a>], a rectangular version of Kris Burm’s hexagonal game <a href="http://www.gipf.com/dvonn/">Dvonn</a>. Now, Burm is a genius, and Dvonn is a fascinating game just the way it is, and the world doesn&#8217;t really need a watered-down rectangular version of it. But I wanted a board game to use as the basis for a sample application for my Test-Driven Development workshops, and hexagonal grids are just too much to ask of workshop participants. So Towers was born.</p>




<p>My goal was to code the first few basic features of the game myself, such as moving one tower onto another. And I would include some smelly code for participants to refactor. Over the course of the workshop, participants would write additional features—determining which moves are legal, detecting the end of the game, and so on.</p>




<p>That was my intention.</p>




<p>I started <a href="https://github.com/dhemery/towers.dead">writing the code</a>, and worked on it in rare spare moments over the last eight months. As of a few weeks ago, I&#8217;d gotten the code as complete as I needed for my workshops, and was spinning my wheels, dabbling in various refactorings for my own amusement.</p>




<p><strong>GOOS.</strong> As I was spinning, <a href="https://groups.google.com/forum/#!topic/growing-object-oriented-software/rwxCURI_3kM">a conversation suddenly blossomed</a> in the <em>Growing Object-Oriented Software</em> (GOOS) Google Group, associated with <a href="http://www.amazon.com/exec/obidos/ASIN/0321503627/dalehemery-20">Steve Freeman and Nat Pryce’s terrific book</a> of the same name. Someone had dropped a note pointing to Brain Swan’s provocatively titled presentation “<a href="http://www.testingtv.com/2010/12/20/mocks-suck-and-what-to-do-about-it/">Mocks Suck</a>.” A fascinating dialogue ensued, led by Steve, Nat, Brian, Joe Rainsberger and others.</p>




<p>As I watched that conversation, two things stood out for me. First was that the “tell, don’t ask” principle (aka The Law of Demeter) kept coming up. Second was the repeated assertion that JMock’s strictness (its rejection by default of any method call you didn’t tell it to expect) was not a damned nuisance at all, but actually a good thing, because it points to problems in the code.</p>




<p>Though I’d heard both of these ideas before (I first read about the Law of Demeter in 1990 when I was writing C++ code), and applied them half-heartedly, I’d never given them my full attention. But Steve, Nat, and Joe are all really smart, and I’d learned much from them in the past. So when they all repeated these ideas within a few hours of each other, I sat up and took notice. As they explained their approach to mocking, I began to see that strict mocking and “tell, don’t ask” were at least more nuanced than I’d thought, if not more powerful.</p>




<p><strong>The Itch.</strong>I got the itch to apply these two “new” ideas mindfully. And I added a third idea that I had been practicing for a while, but which suddenly made more sense in light of the GOOS conversation: Develop applications from the outside in.</p>




<p>Suddenly I had a new intention for Towers. In addition to writing a sample application in my workshop, I could also create a workshop for myself, an opportunity to apply these three ideas and see what I could learn.</p>




<p>So I began applying &#8220;tell, don&#8217;t ask&#8221; to my existing Towers code.  After a few days of that I began to feel lost and backed off. (You may follow that trail from <a href="https://github.com/dhemery/towers.dead/commits/master">the clearly marked commit on Jan 12</a> if you wish. I haven&#8217;t the heart.) I spent a day away from the code, then decided to <a href="https://github.com/dhemery/Towers">start the whole app over in a fresh repo</a>.</p>




<p><strong>A Blunt Instrument.</strong> Several coding-hours into my third take, I found myself struggling to configure three different mocks for one class I was testing. After I&#8217;d thrashed a bit, something hit me like a can of Spam to the forehead: This was one of those situations Steve, Nat, and Joe had talked about. The problem was not that the mocks were difficult to set up. The problem was that my simple class required three collaborators.</p>




<p><strong>A Blunter Blunt Instrument.</strong> A few commits later I’d fixed the problem, and was excited by what I’d learned. <a href="https://twitter.com/#!/dhemery/status/26568863437029376">I tweeted</a> (in a way that was perhaps easy to misinterpret as criticism of JMock): “Using JMock for the first time. Noticed 3 mocks in one test. Ugh. Started refactoring. Ended up with one dependency, no mocks.”</p>




<p>Within minutes, <a href="https://twitter.com/#!/sf105/status/26601084311048192">Steve replied</a> “Post example code please?” Seconds later, <a href="https://twitter.com/#!/natpryce/status/26607199987961856">Nat added</a>, “Are you going to write up your experience?”</p>




<p>I promised to post some code, but hesitated about writing up my experience. “I don’t know  yet,” <a href="https://twitter.com/#!/dhemery/status/26609090058780672">I said</a>. “I’m too new with ‘tell, don’t ask’ to have a feel for what I’m doing.”</p>




<p>Then Yves Hanoulle <a href="https://twitter.com/#!/yveshanoulle/status/26613273394679808">hit me with this blunt instrument</a>: “Why is being new an excuse for not writing down?”</p>




<p>Dammit, he’s right. Double dammit.</p>




<p>So I started writing a short blog post about what had happened in the “three mocks” incident. As I scoured my (frequent) git commits to find reference points for my blog post, I found myself studying my process. What had I done? What had my reasoning? What had the results been? Then I discovered that there were things to learn from even earlier in this hours-old project, starting with my very first decision, my choice of “walking skeleton.” And suddenly I was learning from the process of writing.</p>




<p><strong>The Thing.</strong> And that post turned into two. And then I thought I could make it a series (just in case I learn anything else, and just in case that’s interesting to anyone). And then I needed to write this introduction. And now it’s becoming a thing. (Dammit, Yves!)</p>




<p>So this post is my introduction to the thing. Two more posts are in the works, each nearly complete. One describes the &#8220;three mocks&#8221; problem. The other describes the earlier code and the &#8220;walking skeleton&#8221; problem. Beyond that, who knows?</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What JUnit Rules are Good For]]></title>
    <link href="http://cwd.dhemery.com/2011/01/what-junit-rules-are-good-for/"/>
    <updated>2011-01-04T14:20:41-08:00</updated>
    <id>http://cwd.dhemery.com/2011/01/what-junit-rules-are-good-for</id>
    <content type="html"><![CDATA[<p>In <a href="http://cwd.dhemery.com/2010/12/junit-rules/">my previous post, I described how to write JUnit rules</a>. In this post, I&#8217;ll describe some of the things rules are good for, with examples.</p>




<p>Before JUnit runs a test, it knows something about the test. When the test ends, JUnit knows something about the results. Sometimes we want test code to have access to that knowledge, or even to alter details about a test, the results, or the context in which the test runs.</p>




<p>Older versions of JUnit offered no easy way for test code to do those things. Neither test class constructors nor test methods were allowed to take parameters. Each test ran in a hermetically sealed capsule. There was no simple API to access or modify JUnit&#8217;s internal knowledge about a test.</p>




<p>That&#8217;s what rules are for. JUnit rules allow us to:</p>


<ul>
<li>Add information to test results.</li>
<li>Access information about a test before it is run.</li>
<li>Modify a test before running it.</li>
<li>Modify test results.</li>
</ul>




<h3>Adding Information to Test Results</h3>




<p>A few months ago I was working with testers at a client, automating web application tests using Selenium RC. The tests ran under Hudson on our continuous integration servers. The Selenium server ran in the cloud using Sauce Labs&#8217; <a href="http://saucelabs.com/ondemand">Sauce On Demand</a> service.</p>




<p>Information about each test run was available in two places. First, Hudson creates a web page for each test run, including a printout of any exception raised by the test. Second, Sauce On Demand creates a job for each test run, and a web page for each job, which displays a log of every Selenium command and its result, links to screenshots taken just before each Selenium command that would change the state of the browser, and a video of the entire session.</p>




<p>To make it easier to find information about test failures, we wanted a way to link from the Hudson test report to the Sauce Labs job report. Determining the URL to the Sauce Labs job report was easy; our test framework knew how to do that. But we didn&#8217;t know how to insert the URL into the Hudson test report.  Given that we needed to display the URL only when a test failed, we decided that the easiest solution was to somehow catch every exception, and wrap it in a new exception whose message included the URL. When Hudson printed the exception, the printout would display the URL.</p>




<p>The challenge was: How to catch every exception? For the exceptions thrown directly by our own test code, wrapping them was easy. But what to do about exceptions thrown elsewhere, such as by Selenium? Sure, we could wrap every Selenium call in a try/catch block, but that seemed troublesome.</p>




<p>One possibility seemed promising: Given that every exception eventually passed through JUnit, perhaps we could somehow hook into JUnit, and wrap the exception there. But how to hook into JUnit?</p>




<p>I tweeted about the problem. Kent Beck replied, telling me that my problem was just the thing Rules were designed to help with. He also sent me some nice examples of how write a rule and (of course) how to test it.</p>




<p>With Kent&#8217;s helpful advice and examples in hand, I was able to quickly write a rule that did exactly what my client and I needed:</p>




<blockquote><pre>
public class ExceptionWrapperRule implements MethodRule {
    public Statement apply(final Statement base, FrameworkMethod method, Object target) {
        return new Statement() {
            public void evaluate() throws Throwable {
                try {
                    base.evaluate();
                } catch (Throwable cause) {
                    throw new SessionLinkReporter(cause);
                }
            }
        };
    }
}
</pre></blockquote>




<p>In our test code, at the point where we establish the Selenium session, we obtain the session ID from Selenium and stash it. If the test fails, the <code>ExceptionWrapperRule</code>&#8217;s statement catches it and wraps it in a SeleniumLinkReporter (an Exception subclass we defined). The SeleniumLinkReporter constructor retrieves the stashed session ID, builds the Sauce On Demand job report link, and stuffs it into its exception message.</p>




<p>So this is an example of the first major use of rules: To modify test results by adding information obtained during the test.</p>




<h3>Accessing Information About a Test Before It Is Run</h3>




<p>At that same client, we learned of a new Sauce On Demand feature that we wanted to use: <a href="http://saucelabs.com/blog/index.php/2010/08/sauce-tv-screencast-watch-your-tests-run-live-in-the-cloud/">SauceTV</a>. SauceTV displays a video of the browser while your test is running. As we wrote new tests, changed the features of the web application, and accessed new features of Sauce On Demand, we found ourselves often wanting to watch tests as the executed.</p>




<p>Sauce Labs provides a web page that displays two lists of open jobs for your account: Your jobs that are currently running, and your jobs that are queued to run. To access the video for a test in progress, you click the name of the appropriate job.</p>




<p>By default, each job&#8217;s name is its Selenium session ID, a long string of hexadecimal digits. Even if you know the session ID, it is difficult to quickly distinguish one long hexadecimal string from another. To help with this, Sauce Labs allows you to assign each job a descriptive name to display in the job lists. You do this by sending a particular command to its Selenium server.</p>




<p>Given that we were running one test per job, the obvious choice for the job name is the name of the test. But how to access the name of the test? Certainly we could add a line like this to each test:</p>




<blockquote><pre>
@Test public void myTest() {
    sendSauceJobName("myTest");
}
</pre></blockquote>




<p>But that&#8217;s crazy talk. Much better would be a way to detect the test name at runtime, in a single place in the code. How to detect the test name? Rules to the rescue. We wrote this rule:</p>




<blockquote><pre>
public class TestNameSniffer implements MethodRule {
    private String testName;

    public Statement apply(Statement statement, FrameworkMethod method, Object target) {
        String className = method.getMethod().getDeclaringClass().getSimpleName();
        String methodName = method.getName();
        testName = String.format("%s.%s()", className, methodName);
        return statement;
    }
    
    public String testName() {
        return testName;
    }
}
</pre></blockquote>




<p>The rule stashes the test name, and other code later sends the name to Selenium RC. Now Sauce Labs labels each job with the name of the test, which is much easier to recognize than hexadecimal strings.</p>




<h3>Modifying a Test Before Running It</h3>




<p>In a Twitter conversation about what rules are good for, <a href="http://twitter.com/natpryce/status/14970733117579264">Nat Price said</a>, &#8220;JMock uses a rule to perform the verify step after the test but before tear-down.&#8221; JMock is a framework that makes it easy to create controllable collaborators for the code you&#8217;re testing, and to observe whether your code interacts with them in the ways you intend.</p>




<p>To <a href="http://www.jmock.org/">use JMock in your test code</a>, you declare a field that is an instance of the JUnitRuleMockery class:</p>


<blockquote><pre>
public class MyTestClass {
    @Rule
    public JUnitRuleMockery context = new JUnitRuleMockery();
    
    @Mock
    public ACollaboratorClass aCollaborator;
    
    @Test
    public void myTest() {
        ... // Declare expectations for aCollaborator.
        ... // Invoke the method being tested.
    }
}
</pre></blockquote>




<p>JUnitRuleMockery is a rule whose <code>apply()</code> looks like this:</p>




<blockquote><pre>
@Override
public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            prepare(target);
            base.evaluate();
            assertIsSatisfied();
        }
        
        ... // Declarations of prepare() and assertIsSatisfied()
    }
}
</pre></blockquote>




<p>Before the statement executes the test, it first calls <code>prepare()</code>, which initializes each mock collaborator field declared by the test class. For the example test class, <code>prepare()</code> initializes <code>aCollaborator</code> with a mock instance of <code>ACollaboratorClass</code>.</p>




<p>Initializing fields in the target is an example of a second use for rules: Modifying a test before running it.</p>




<h3>Modifying Test Results</h3>




<p>The JMock code also demonstrates another use for JUnit rules: Modifying test results. After the test method runs, the <code>assertIsSatisfied()</code> method evaluates whether the expectations expressed by the test method are satisfied and throws an exception if they are not. Even if no exception was thrown during the test method itself, the rule might throw an exception, thereby changing a test from passed to failed.</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using Rules to Influence JUnit Test Execution]]></title>
    <link href="http://cwd.dhemery.com/2010/12/junit-rules/"/>
    <updated>2010-12-15T05:26:12-08:00</updated>
    <id>http://cwd.dhemery.com/2010/12/junit-rules</id>
    <content type="html"><![CDATA[<p>JUnit rules allow you to write code to inspect a test before it is run, modify whether and how to run the test, and inspect and modify test results. I&#8217;ve used rules for several purposes:</p>


<ul>
<li>Before running a test, send the name of the test to Sauce Labs to create captions for SauceTV.</li>
<li>Instruct Swing to run a test headless.</li>
<li>Insert the Selenium session ID into the exception message of a failed test.</li>
</ul>




<h3>Overview of Rules</h3>




<p><strong>Parts.</strong> The JUnit rule mechanism includes three main parts:</p>


<ul>
<li>Statements, which run tests.</li>
<li>Rules, which choose which statements to use to run tests.</li>
<li><code>@Rule</code> annotations, which tell JUnit which rules to apply to your test class.</li>
</ul>




<p><strong>Flow.</strong> To execute each test method, JUnit conceptually follows this flow:</p>


<ol>
<li>Create a default statement to run the test.</li>
<li>Find all of test class&#8217;s rules by looking for public member fields annotated with <code>@Rule</code>.</li>
<li>Call each rule&#8217;s <code>apply()</code> method, telling it which test class and method are to be run, and what statement JUnit has gathered so far. <code>apply()</code> decides how to run the test, selects or creates the appropriate statement to run the test, and returns that statement to JUnit. JUNit then passes this statement to the next rule&#8217;s apply() method, and so on.</li>
<li>Run the test by calling the <code>evaluate()</code> method of the statement returned by the last rule.</li>
</ol>




<p>I&#8217;ll describe the flow in more detail in the final section, below. Now let&#8217;s take a closer look at the parts, with an example. (The code snippets are available as <a href="https://gist.github.com/741341">a gist on GitHub</a>.)</p>




<h3>Writing Statements</h3>




<p>A statement executes a test, and optionally does other work before and after executing the test. You write a new statement by extending the abstract <code>Statement</code> class, which declares a single method:</p>


<blockquote><pre>
public abstract void evaluate() throws Throwable;
</pre></blockquote>




<p>A typical <code>evaluate()</code> method acts as a wrapper around another statement. That is, it does something before the test, calls another statement&#8217;s <code>evaluate()</code> method to execute the test, then does something after the test.</p>




<p>Here is an example of a statement that invokes the base statement to run the test, then takes a screenshot if the test fails:</p>


<blockquote><pre>
public class MyTest {
    @Rule
    public MethodRule screenshot = new ScreenshotOnFailureRule();

    @Test
    public void myTest() { ... }

    ...
}
</pre></blockquote>




<h3>Writing Rules</h3>




<p>A rule chooses which statement JUnit will use to run a test. You write a new rule by implementing the <code>MethodRule</code> interface, which declares a single method:</p>


<blockquote><pre>
Statement apply(Statement base, FrameworkMethod method, Object target);
</pre></blockquote>


<p>The parameters are:</p>


<ul>
<li><code>method</code>: A description of the test method to be invoked.</li>
<li><code>target</code>: The test class instance on which the method will be invoked.</li>
<li><code>base</code>: The statement that JUnit has gathered so far as it applies rules. This may be default statement that JUnit created, or a statement created by another rule.</li>
</ul>




<p>The purpose of <code>apply()</code> is to produce a statement that JUnit will later execute to run the test. A typical <code>apply()</code> method has two steps:</p>


<ol>
<li>Create a statement instance.</li>
<li>Return the newly created statement to JUnit.</li>
</ol>




<p>Note that when JUnit later calls the statement&#8217;s <code>evaluate()</code> method, it does not pass any information. If the statement needs information about the test method, the test class, how to invoke the test, or anything else, you will need to supply that information to the statement yourself (e.g. via the constructor) before returning from <code>apply()</code>.</p>




<p>Almost always you will pass <code>base</code> to the new statement&#8217;s constructor, so that the statement can call <code>base</code>&#8217;s <code>evaluate()</code> method at the appropriate time. Some statements need information extracted from <code>method</code>, such as the method name or the name of the class on which the method was declared. Others do not need information about the method. It&#8217;s rare that a statement will need information about <code>target</code>. (The only one I&#8217;ve seen is the default one that JUnit creates to invoke the test method directly.)</p>




<p>Often, there is no decision to make. Simply create the statement and return it, as in this example:</p>


<blockquote><pre>
public class ScreenshotOnFailureRule implements MethodRule {
    @Override
    public Statement apply(Statement base, FrameworkMethod method, Object target) {
        String className = method.getMethod().getDeclaringClass().getSimpleName();
        String methodName = method.getName();
        return new ScreenshotOnFailureStatement(base, className, methodName);
    }
}
</pre></blockquote>




<p>In situations that are not so simple, you can compute the appropriate statement depending on information about the test method. For example, you may wish to suppress screenshots for certain tests, which you indicate the <code>@NoScreenshot</code> annotation. Your screenshot rule can choose the appropriate statement depending on whether the annotation is present on the method:</p>


<blockquote><pre>
public class ScreenshotOnFailureRule implements MethodRule {
    @Override
    public Statement apply(Statement base, FrameworkMethod method, Object target) {
        if(allowsScreenshot(method)) {
            String className = method.getMethod().getDeclaringClass().getSimpleName();
            String methodName = method.getName();
            return new ScreenshotOnFailureStatement(base, className, methodName);
        }
        else {
            return base;
        }
    }

    private boolean allowsScreenshot(FrameworkMethod method) {
        return method.getAnnotation(NoScreenshot.class) == null;
    }
}
</pre></blockquote>




<h4>A note about upcoming changes in the rule API</h4>




<p>In JUnit 4.9&#8212;the next release of JUnit&#8212;the way you declare rules will change slightly. The <code>MethodRule</code> interface will be deprecated, and the <code>TestRule</code> interface added in its place. The signature of the <code>apply()</code> method differs slightly between the two interfaces. As noted above, the signature in the deprecated <code>MethodRule</code> interface was:</p>




<blockquote><pre>
Statement apply(Statement base, FrameworkMethod method, Object target);
</pre></blockquote>




<p>The signature in the new <code>TestRule</code> interface is:</p>




<blockquote><pre>
Statement apply(Statement base, Description description);
</pre></blockquote>




<p>Instead of using a <code>FramewordMethod</code> object to describe the test method, the new interface uses a <code>Description</code> object, which gives access to essentially the same information. The <code>target</code> object (the instance of the test class) is no longer provided.</p>




<h3>Applying Rules</h3>




<p>To use a rule in your test class, you declare a public member field, initialize the field with an instance of your rule class, and annotate the field with <code>@Rule</code>:</p>




<blockquote><pre>
public class MyTest {
    @Rule
    public MethodRule screenshot = new ScreenshotOnFailureRule();

    @Test
    public void myTest() { ... }

    ...
}
</pre></blockquote>




<h3>The Sequence of Events In Detail</h3>




<p>JUnit now applies the rule to every test method in your test class. Here is the sequence of events that occurs for each test (omitting details that aren&#8217;t related to rules):</p>


<ol>
<li>JUnit creates an instance of your test class.</li>
<li>JUnit creates a default statement whose <code>evaluate()</code> method knows how to call your test method directly.</li>
<li>JUnit inspects the test class to find fields annotated with <code>@Rule</code>, and finds the <code>screenshot</code> field.</li>
<li>JUnit calls <code>screenshot.apply()</code>, passing it the default statement, the instance of the test class, and information about the test method.</li>
<li>The <code>apply()</code> method creates a new <code>ScreenshotOnFailureStatement</code>, passing it the default statement and the names of the test class and test method.</li>
<li>The <code>ScreenshotOnFailure()</code> constructor stashes the default statement, the test class name, and the test method name for use later.</li>
<li>The <code>apply()</code> method returns the newly constructed screenshot statement to JUnit.</li>
<li>(If there were other rules on your test class, JUnit would call the next one, passing it the statement created by your screenshot rule. But in this case, JUnit finds no further rules to apply.)</li>
<li>JUnit calls the screenshot statement&#8217;s <code>evaluate()</code> method.</li>
<li>The screenshot statement&#8217;s <code>evaluate()</code> method calls the default statement&#8217;s <code>evaluate()</code> method.</li>
<li>The default statement&#8217;s <code>evaluate()</code> method invokes the test method on the test class instance.</li>
<li>(Let&#8217;s suppose that the test method throws an exception.)</li>
<li>Your screenshot statement&#8217;s <code>evaluate()</code> method catches the exception, calls the <code>MyScreenshooter</code> class to take the screenshot, and rethrows the caught exception.</li>
<li>JUnit catches the exception and does whatever arcane things it does when tests fail.</li>
</ol>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[One Small Thing]]></title>
    <link href="http://cwd.dhemery.com/2010/12/one-small-thing/"/>
    <updated>2010-12-13T12:55:26-08:00</updated>
    <id>http://cwd.dhemery.com/2010/12/one-small-thing</id>
    <content type="html"><![CDATA[<p>At the end of a workshop in 1997, I offered a clichéd end-of-training activity: &#8220;How will you use what you&#8217;ve learned in this workshop? Write that down.&#8221; A few people started to write. More people looked uncomfortable. More than half seemed to check out mentally, and two began to check out physically, gathering their belongings to leave.</p>




<p>In the spur of the moment, I invented an elaboration: &#8220;What one small thing will you commit to doing? What&#8217;s the smallest thing you can commit to?&#8221;

<p>One man asked, &#8220;How small?&#8221; I said, &#8220;Smaller than that.&#8221; He laughed, because my kinda non-answer answer seemed funny. Then he immediately thought of something. &#8220;Aha!&#8221; he said, and started to write. Another man still didn&#8217;t understand, so I offered a bound: &#8220;Something you could do all on your own before noon on Monday.&#8221; That made sense to him, and he began to write. And everybody else wrote. The two people who had started to gather their belongings sat down and wrote.</p>

<p>That spontaneous refinement worked so well that I now often end workshops with the One Small Thing activity: <strong>What one small thing will you commit to doing? Something you could do all on your own before noon? Write it down.</strong></p>

<p>Over the years I&#8217;ve learned what makes this simple activity so powerful. First, people can almost always find something to commit to. If they are reluctant to commit to a given action, there&#8217;s almost always a smaller action that they will commit to fully, with enthusiasm. One small thing. How small? Smaller than that. What kind of thing? Anything that you will commit to.</p>

<p>Second, when invited to commit to one small thing, people always find something that matters to them. So small doesn&#8217;t mean unimportant.</p>

<p>Third, people are good at keeping small commitments. Keeping one small commitment starts a ball rolling&#8212;or continues one, for people who already make and keep personal commitments.</p>

<p>Fourth, once people see that keeping even a small commitment has good effects, and feels good in and of itself, they realize that they can make their lives better even in small steps.</p>

</p>


<p>When people finish writing, I invite them to share their commitments if they wish. Almost always there&#8217;s a pause. Then someone shares. Then someone else. After the first few, other people begin to feel safer. Usually about a third of the people in the room will share their commitments, and then we&#8217;re done.</p></p>

<p>As I invite people to share, I make it clear that sharing is entirely voluntary, and that it&#8217;s okay to keep these commitments private and personal. At a recent workshop, one woman approached me after the activity and said, &#8220;Originally I wrote down something I didn&#8217;t really care about. When I saw that you really weren&#8217;t going to make us say our commitments out loud, I realized that this wasn&#8217;t for you, it was for me. So I changed my commitment to something that matters to me. It matters a lot.&#8221;</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Certification Prime Directive]]></title>
    <link href="http://cwd.dhemery.com/2010/11/certification-prime-directive/"/>
    <updated>2010-11-04T13:54:47-07:00</updated>
    <id>http://cwd.dhemery.com/2010/11/certification-prime-directive</id>
    <content type="html"><![CDATA[<p>The demand for certifications comes ultimately from hirers—in particular, from hirers who need to hire and retain highly skilled practitioners, and who are not themselves able to assess practitioners’ skills. Though certification programs may serve other needs, the hirers’ needs are the heart that pumps life into any certification.</p>




<p>Imagine a certification that no hirer cared about, that no hirer ever used as a factor when determining whether to hire someone, or how much to pay them. Would such a certification thrive as a certification? Would it survive? If the certification offered sufficient prestige, some practitioners may seek it as a badge of honor, a point of pride. But as a certification <em>per se?</em></p>




<p>Hirers who can accept moderate or low skill don’t need certifications. Hirers who can assess skills themselves don’t need certifications. Certifications matter because hirers need help assessing skills that matter.</p>




<p>I offer this test of the value and legitimacy of a certification program: <em>To what extent does it help hirers make high quality hiring decisions?</em></p>




<p>Whatever benefits of a certification program may provide for others, they are secondary. Any certification program that serves other needs for other people, but does not help hirers make high quality hiring decisions, is a swindle. Any certification program that serves other people’s needs at the expense of those hirers’ needs is a fraud.</p>




<p>I propose <strong>The Certification Prime Directive: Above all else, help hirers make high quality hiring decisions.</strong></p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Questions to Explore Problems]]></title>
    <link href="http://cwd.dhemery.com/2010/08/questions-to-explore-problems/"/>
    <updated>2010-08-30T12:16:56-07:00</updated>
    <id>http://cwd.dhemery.com/2010/08/questions-to-explore-problems</id>
    <content type="html"><![CDATA[<p>One of the most powerful things you can do to help someone solve a problem is to ask great questions. My new article &#8221;<a href="http://dhemery.com/pdf/questions_to_explore_problems.pdf">Questions to Explore Problems</a>&#8221; (PDF) gives dozens of questions that I’ve found essential in my work as a coach, including questions to explore:</p></p>

<ul>
<li>The problem in general.</li>
<li>The desired state, the perceived state, and the difference between the two.</li>
<li>The way the problem is stated.</li>
<li>The problem&#8217;s past, present, and future.</li>
<li>The way the problem is being solved.</li>
<li>The way you are exploring the problem.</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Human Bias Toward Standards of Perfection]]></title>
    <link href="http://cwd.dhemery.com/2010/07/perfection/"/>
    <updated>2010-07-29T12:29:47-07:00</updated>
    <id>http://cwd.dhemery.com/2010/07/perfection</id>
    <content type="html"><![CDATA[<p>In <a href="http://www.ted.com/talks/laurie_santos.html">a fascinating TED Talk</a>, Laurie Santos shows that monkeys make the same kinds of economic errors as humans do. Another way to say this: Humans make some of the same kinds of economic errors as monkeys do.</p>




<p>Early in the video, Santos asked a question that caught my attention: &#8220;How is a species that&#8217;s as smart as we are capable of such bad and consistent errors?&#8221;</p>




<p>What I find most interesting about Santos’s question is a presupposition: The question tacitly posits “as smart as we are” as the standard of judgment. Why do I say “tacitly,” when she clearly states the standard in her question? Though the standard is explicit, what’s tacit is <em>taking that standard as a given.</em></p>




<p>To demonstrate, I’ll ask a different question: “For a species that consistently makes such bad errors, how is it that we are as smart as we are?” My question posits a different baseline for evaluating our behavior: Our consistent errors.</p>




<p>In my tweets on this subject, I called Santos’s question a “foreground/background error.” That was a mistake. Rather, Santos makes a foreground/background <em>choice</em>. Her question and mine differ in the choice of background and foreground. Her question places human smartness in the background and consistent errors in the foreground. My question reverses the foreground and background.</p>




<p>We humans often ask such questions, which make an implicit choice of what to place in the foreground and what in the background.</p>




<p>For example, people ask, “Why do we sleep?” The question (tacitly) takes <em>awakeness</em> as background. I think it’s probably more reasonable and fruitful to ask, “Why are we ever wake?” The vast majority of living things are never awake. We and other animals do sometimes wake. How does that happen? I think it’s miraculous.</p>




<p>Another example, which I hear a lot: “Why do we miscommunicate so much?” Flip the foreground and background: “How is it that we are ever able to communicate at all?”  Communication is a freaking miracle, and our oft-uttered question takes it for granted.</p>




<p>Matt Heusser tweeted <a href="http://twitter.com/mheusser/status/19842480608">another example</a> from a forum on communication between managers and doers: “Why is there so much friction between managers and doers?” Matt <a href="http://twitter.com/mheusser/status/19842514450">flipped the question</a>: “With so much conflict inherent in our systems, isn’t it a miracle that we ever get anything done?”</p>




<p>We could state our observations relatively neutrally, with equal emphasis: We&#8217;re as smart as we are; we consistently make bad errors. But typically we don&#8217;t do that. We place one observation in the background, and apply it as a standard against which to judge the other observation.</p>




<p>What fascinates me is that our questions typically place the more “perfect” standard in the background, even though the evidence suggests that humans don’t live up to the standard. What&#8217;s more, we typically ask such questions directly in response to noticing that we don&#8217;t live up to the standard. We take as given a standard that we know we don’t meet. We humans seem to have a bias toward judging ourselves against standards of perfection.</p>




<p>This is not an idle topic for me. It&#8217;s at the heart of my coaching. My clients often lament that they fall short of some standard they have set for themselves. As we explore the standard, we often find that the standard is very difficult to meet, and sometimes beyond human capability. And yet clients make great effort to continue to hold onto their standards, even after agreeing that the standards are unreasonable.</p>




<p>How come we so often choose as background a standard that we clearly do not meet? What would happen if we more often made a different choice, to take <em>our typical experience</em> as the standard, and ask how we are sometimes able to be better than that?</p>




<p>What if <em>how actually we observe ourselves to be</em> were okay, even as we yearn to be “better”?</p>




<p>Of course, my entire post implicitly posits its own standard of perfection: A standard of not judging ourselves against standards that we demonstrably fail to live up to.</p>




<p>Maybe I can soften my own error this way: When we notice that we are holding ourselves and each other to some standard of perfection, we have an opportunity to make the standard explicit, ask whether and how it serves us, and explore other standards that may serve us better.</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Bob and Dale Chat about Social Challenges at Work]]></title>
    <link href="http://cwd.dhemery.com/2010/06/agile-toolkit-podcast/"/>
    <updated>2010-06-20T12:03:55-07:00</updated>
    <id>http://cwd.dhemery.com/2010/06/agile-toolkit-podcast</id>
    <content type="html"><![CDATA[<p>A few weeks ago, at Agile Development Practices West 2010 conference in Las Vegas, my friend and colleague <a href="http://electroglide.biz/">Bob Payne</a> hosted me for an episode of his Agile Toolkit podcast. I invite you to listen to <a href="http://bit.ly/cQFhIW">our half-hour conversation</a> and to <a href="http://agiletoolkit.libsyn.com/">other episodes</a> about all things Agile.</p>




<p>Bob&#8217;s podcasts are always conversational&#8212;the conversation wanders where it will, but seldom strays far from the topic du jour. Our wanderings touched on:</p>




<ul>
<li>Resistance is mutual</li>
<li>Bridging the gap between hamsters and wolverines</li>
<li>Solving the deeper problem is sometimes easier than solving the surface problem</li>
<li>Ineffective patterns of coping with stress (blaming, placating, distracting)</li>
<li>Joe diffuses the boss&#8217;s boss&#8217;s boss&#8217;s boss&#8217;s boss&#8217;s blaming</li>
<li><a href="http://cwd.dhemery.com/2004/04/aggregation/">The power of aggregation</a></li>
<li>The power of giving yourself choices</li>
<li><a href="http://catalysisgroup.com">Payson Hall&#8217;s</a> terrific keynote about the dilemmas of risk management</li>
<li>Dale fails to grok space and time</li>
<li>Three definitions of resistance</li>
<li><em>Overcoming</em> resistance (boo!) versus <em>resolving</em> resistance (yay!)</li>
<li><a href="http://dhemery.com/articles/resistance_as_a_resource/">Resistance is feedback</a></li>
<li>To encourage change, start by <a href="http://cwd.dhemery.com/2003/05/meet_people_where_they_are/">meeting people where they are</a></li>
<li>Two styles of Agile adoption: &#8220;By the book&#8221; and evolutionary</li>
<li>From balance to differentiation&#8212;from &#8220;how much&#8221; to &#8220;which&#8221;</li>
<li>My upcoming <a href="http://bit.ly/cUcxGx">Resistance as a Resource</a> workshop at <a href="http://agilistry.com">Agilistry Studio</a>, July 14&#8211;15</li>
</ul>




<p>Only in retrospect could I name the central topic of our chat: social challenges at work. In further retrospect, that central topic is nearly inevitable, given my interests.</p>


<!-- 3bf8311dc8f444938c43e30d0ed83947  -->

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Problem Statement Smells]]></title>
    <link href="http://cwd.dhemery.com/2010/06/smells/"/>
    <updated>2010-06-05T16:15:41-07:00</updated>
    <id>http://cwd.dhemery.com/2010/06/smells</id>
    <content type="html"><![CDATA[<h3>&nbsp;</h3>




<h3>Problems and Problem Statements</h3>




<p>In <em><a href="http://www.amazon.com/exec/obidos/ASIN/0932633161/dalehemery-20">Are Your Lights On?</a></em>, Don Gause and Jerry Weinberg offer this useful definition of <em>problem</em>:</p>




<blockquote><em>A problem is a difference between things as perceived and things as desired.</em></blockquote>




<p>I like this definition because it highlights three important elements of any problem: things as perceived, things as desired, and a difference between the two.</p>




<p>There’s another important element of any problem:  The person who is perceiving and desiring things.  In order for the difference between things as perceived and things as desired to be a problem, the perceiver and the desirer must be the same person.</p>




<p>A problem statement is a model of the problem, a simplification designed to aid in solving the problem. Like any model, a problem statement differs from the thing being modeled. A good model highlights features that are most relevant to the modeler’s purpose and hides details that are less relevant. A good problem statement highlights problem elements that help solve the problem, and hides details that distract.</p>




<h3>Problem Statement Smells</h3>




<p>A <em>problem statement smell</em> is any element of a problem statement that makes the problem harder to solve. Some smells attract your attention toward conditions that are inessential to the problem, or that are beyond your influence. Some smells divert your attention away from an essential element of the problem.</p>




<p>Problem statement smells commonly take three forms: additions, deletions, and distortions. Some problem statements combine several smells.</p>




<h3>Additions</h3>




<p>Some problem statements introduce claims and ideas that are not present in the problem itself. These additions can confuse problem solvers, lead to wild goose chases, or otherwise distract from the problem.</p>




<p><strong>Conclusions expressed as facts.</strong> <em>I need to give my boss the test results for third-party authorization, but Jeff isn’t done testing it yet.</em> How do you know Jeff isn’t done? What did you see or hear that led to that conclusion? Perhaps Jeff is already done, and is writing up his report right now.</p>




<p><strong>Mindreading.</strong> <em>Jeff is just trying to protect his own turf.</em> You have no direct access to Jeff’s thoughts and intentions. What did you see or hear that led to that conclusion? What are two other possible meanings of what you saw and heard?</p>




<p><strong>Solution probleming.</strong> <em>The problem is that we don’t have a Wiki for test status.</em> This is a solution in search of a problem. What’s the problem? If you had a Wiki, what would that do for you? Often, the “problem behind the problem” is easier to solve.</p>




<p><strong>Missing standard.</strong> <em>Jeff tests too slowly.</em> Too slowly for what? What would be fast enough? How do you assess how fast he tests?</p>




<h3>Deletions</h3>




<p>Many problem statements omit important elements of the problem. These omissions can make it harder to envision what a solution would look like.</p>




<p><strong>Missing desire.</strong> <em>The problem is that Jeff is only halfway finished testing third-party authorization.</em> That’s the perceived state. What’s the desired state?</p>




<p><strong>Missing perception.</strong> <em>The problem is that I need Jeff to finish testing third-party authorization by Monday.</em> That’s the desired state. What’s the perceived state?</p>




<p><strong>Missing problem stater.</strong><em> The problem is that Jeff is supposed to be done testing third-party authorization, and he isn’t done yet.</em> The person who stated the problem is mentioned nowhere in the problem statement. Who is doing the supposing? Whose problem is this?</p>




<p><strong>Missing actor.</strong> <em>Some of the items on the backlog seem to have no owner.</em> Rephrase to add an actor: I cannot identify the owner for some of the backlog items.</p>




<h3>Distortions</h3>




<p>Many problem statements amplify problem elements, or dampen them, or interpret them in distorted ways. Such distortions, if we take them as truths, limit the kinds of solutions we will consider.</p>




<p><strong>“Can’t.”</strong> <em>I can’t ask for a bigger budget.</em> Try: “I choose not to ask for a bigger budget because I want _____.” (Fill in the blank.) What stops you from asking for a bigger budget? What would happen if you asked for a bigger budget?</p>




<p><strong>“Have to.”</strong> <em>I have to work this weekend.</em> Try: “I choose to work this weekend because I want _____.” (Fill in the blank.) What would happen if you didn’t work this weekend?</p>




<p><strong>Inanimate agent.</strong> <em>The problem is that our backlog just keeps growing.</em> Backlogs can’t just grow of their own accord. Somebody is growing it. Who? How?</p>




<p><strong>Lullaby language.</strong> <em>No problem. We should just work weekends until we ship.</em> Words and phrases such as <em>should</em>, <em>no problem</em>, and <em>just</em> tend to minimize the complexity of the problem, directing attention away from important details. Question each use of these “lullaby words” to surface the hidden assumptions. See Jerry Weinberg&#8217;s <em><a href="http://www.amazon.com/exec/obidos/ASIN/0932633528/dalehemery-20">More Secrets of Consulting</a></em> for further examples of lullaby language.</p>




<h3>Combinations</h3>




<p>Sometimes a single problem statement will include a combination of additions, deletions, and distortions.</p>




<p><strong>Judgment.</strong> <em>The problem is that Jeff has no initiative.</em> One smell: mindreading. What do you see and hear that leads you to this conclusion? Another smell: missing desire. What do you want from Jeff? A third smell: tacit causation. Even if Jeff had tons of initiative, he might apply it elsewhere, and still not do what you need.</p>




<p><strong>Tacit causation.</strong> <em>Customers expect me to remember all of their requests, so I add them to the backlog, and the backlog just keeps getting bigger.</em> The little word “so” suggests causation, but the link between cause and effect is neither obvious nor stated. But there is no law of the universe that says “if customers expect you to remember their requests, you must add them to the backlog.” That’s one way to respond to the expectation. What are some other ways?</p>




<p><strong>Other time or place.</strong> <em>Jeff didn’t finish testing third-party authorization.</em> That’s in the past, and you can’t alter that. What problem are you experiencing right now? What need is currently unfulfilled?</p>




<h3>Your Turn</h3>




<p><strong>Experiment:</strong> What other problem statement smells can you identify? How might you remedy each?</p>




<p><strong>Experiment:</strong> In my description of each problem statement smell, I describe or hint at some of the problems caused by the smell. My problem statements have smells. What smells can you identify?</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Four Layers in Automated Tests]]></title>
    <link href="http://cwd.dhemery.com/2010/03/layers/"/>
    <updated>2010-03-15T17:16:15-07:00</updated>
    <id>http://cwd.dhemery.com/2010/03/layers</id>
    <content type="html"><![CDATA[<p>I’ve known for a while that when I automate tests, layers emerge in the automation. Each chunk of automation code relies on lower-level chunks. In <a href="http://code.google.com/p/robotframework/">Robot Framework</a>, for example, tests invoke “keywords” that themselves invoke lower-level keywords.</p>




<p>The layering <em>per se</em> wasn’t a surprise, because automated tests are software, and software tends to organize into layers. But lately I’ve noticed a pattern. The layers in my automated tests center around four themes:</p>




<ul>
<li>Test intentions</li>
<li>System responsibilities</li>
<li>Essential system interface</li>
<li>System implementation interface</li>
</ul>




<p><strong>Test intentions.</strong> Test names and suite names are the top layer in my automation. If I’ve named each test and suite well, the names express my test intentions. Reading through the test names, and seeing how they’re organized into suites, will give useful information about what I tested and why.</p>




<p>For example, in my article on <a href="http://dhemery.com/pdf/writing_maintainable_automated_acceptance_tests.pdf">“Writing Maintainable Automated Acceptance Tests” (PDF)</a>, I was writing tests for a system’s account creation feature, and specifically for the account creation’s responsibility to validate passwords. I ended up with these test names (see Listing 7):</p>




<ul>
<li>Rejects passwords that omit required character types</li>
<li>Rejects passwords with bad lengths</li>
<li>Accepts minimum and maximum length passwords</li>
</ul>




<p>In <a href="http://blog.objectmentor.com/articles/2009/12/07/writing-maintainable-automated-acceptance-tests">an excellent video followup</a> to my article, Bob Martin organized his tests differently, using <a href="http://fitnesse.org/">FitNesse</a>. He grouped tests into two well-named suites, “Valid passwords” and “Invalid passwords.” Each suite includes a number of relevant example passwords, each described with a comment that expresses what makes the example interesting.</p>




<p>Every test tool that I’ve used offers at least one excellent way to express the intentions of each test. However expressed, those intentions become the top layer of my automated tests.</p>




<p><strong>System responsibilities.</strong> A core reason for testing is to learn whether the system meets its responsibilities. As I refine my automation, refactoring it to express my intentions with precision, I end up naming specific system responsibilities directly.</p>




<p>In my article, I’m testing a specific pair of responsibilities: The account creation command must accept valid passwords and reject invalid ones. As I refactored the duplication out of my initial awkward tests, these responsibilities emerged clearly, expressed in the names of two new keywords: Accepts Password and Rejects Password. Listing 7 shows how my top-level tests build on these two keywords.</p>




<p><strong>Essential system interface.</strong> By system interface, I mean the set of messages that the system sends and receives, whether initiated by users (e.g. commands sent to the system) or by the system (e.g. notifications sent to users).</p>




<p>By essential I mean independent of the technology used to implement the system. For example, the account creation feature must offer some way for a user to command the system to create an account, and it must include some way for the system to notify the user of the result of the command. This is true regardless of whether the system is implemented as a command line app, a web app, or a GUI app.</p>




<p>As I write and refine automated tests, I end up naming each of these essential messages somewhere in my code. In my article, Listing 2 defines two keywords. “Create Account” clearly identifies one message in the essential system interface. Though the other keyword, “Status Should Be,” is slightly less clear, it still suggests that the system emits a status in response to a command to create an account. (Perhaps there’s a better name that I haven’t thought of yet.) Listing 4 shows how the higher-level system responsibility keywords build upon these essential system interface keywords.</p>




<p><strong>System implementation interface.</strong> The bottom layer (from the point of view of automating tests) is the system implementation interface. This is the interface through which our tests interact most directly with the system. Sometimes this interaction is direct, e.g. when Java code in our low-level test fixtures invoke Java methods in the system under test. Other times the interaction is indirect, through an intermediary tool, e.g. when we use <a href="http://seleniumhq.org/">Selenium</a> to interact with a web app or <a href="http://easytesting.org/swing/wiki/pmwiki.php">FEST-Swing</a> to interact with a Java Swing app.</p>




<p>In my article, I tested two different implementations of the account creation feature. The first was a command line application, which the tests invoked through the “Run” keyword, an intermediary built into Robot Framework. Listing 2 shows how the Create Account keyword builds on top of the Run keyword (though you’ll have to parse through the syntax junk to find it).</p>




<p>The second implementation was a web app, which the tests invoked through <a href="http://code.google.com/p/robotframework-seleniumlibrary/">Robot Framework’s Selenium Library</a>, an intermediary which itself interacts through Selenium, yet another intermediary. Listing 8 shows how the revised Create Account keyword builds on various keywords in the Selenium Library.</p>


<p><strong>Translating Between Layers</strong></p>

<p>Each chunk of test automation code translates an idea from one layer to the next lower layer. Listing 7 shows test ideas invoking system responsibilities. Listing  4 shows responsibilities invoking messages in the essential system interface. Listings 2 and 8 show how the essential system interface invokes two different system implementation interfaces.</p>




<p>Each of the acceptance test tools I use allows you to build layers like this. In FitNesse, top-level tests expressed in test tables may invoke “scenarios,” which are themselves written in FitNesse tables. And scenarios may invoke lower-level scenarios. In <a href="http://cukes.info/">Cucumber</a>, top-level “scenarios” invoke “test steps,” which may themselves invoke lower-level test steps. In <a href="http://www.thoughtworks-studios.com/agile-test-automation">Twist</a>, “test scenarios” invoke lower-level “concepts” and “contexts.” Each tool offers ways to build higher layers on top of lower layers, which build upon yet lower layers, until we reach the layer that interacts directly with the system we’re testing.</p>




<p>In the examples in my article, I chose to write all of my code in Robot Framework’s keyword-based test language. I defined each keyword entirely in terms of lower-level keywords. I could have chosen otherwise. At any layer, I could have translated from the keyword-based language to a more general purpose programming language such as Java, Ruby, or Python. The other tools I use offer a similar choice.</p>




<p>But I, like many users, find these tools’ test languages easier for non-technical people to understand, and sufficiently flexible to allow users to write tests in a variety of ways. In general, I want as many of these layers as possible to be meaningful not just to technical people, but to anyone who has knowledge of the application domain. So I like to stay with the tool’s test language for all of these layers, switching to a general purpose programming language only at the lowest layer, and then only when the system’s implementation interface forces me to.</p>


<p><strong>A Lens, Not a Straightjacket</strong></p>

<p>When I write automated tests for more complex applications, there are often more layers than these. Yet these four jump out at me, perhaps because each represents a layer of meaning that I always care about. Every automated test suite involves test ideas, system responsibilities, the essential system interface, and the system’s implementation interface. Though other layers arise, I haven’t yet identified additional layers that are so universally meaningful to me.</p>




<p>These layers were a discovery for me. They offer an interesting way to look at my test code to see whether I’ve expressed important ideas directly and clearly. I don’t see them as a standard to apply, or a procrustean template to wedge my tests into. They are a useful lens.</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Tradeoffs]]></title>
    <link href="http://cwd.dhemery.com/2009/12/tradeoffs/"/>
    <updated>2009-12-09T12:15:00-08:00</updated>
    <id>http://cwd.dhemery.com/2009/12/tradeoffs</id>
    <content type="html"><![CDATA[<p>In a thoughful comment on <a href="http://cwd.dhemery.com/2009/11/wmaat/">my blog post</a> about writing maintainable automated acceptance tests, <a href="http://cwd.dhemery.com/2009/11/wmaat/#comment-18843">Chris Falter suggested</a> a different way to name the variables in my test cases. He mentions that our two naming styles present a tradeoff, and that set me on a long trail of thought.</p>

<p>I&#8217;m fascinated by tradeoffs, and I often drive myself nuts making them &#8211; I go back and forth and back and forth and&#8230; And at some point, I&#8217;ll identify the qualities that I&#8217;m trying to trade off (expressiveness, test speed, number of places I&#8217;d have to change if the code or the requirements change) and move on. Until the next time I visit that file. Then I&#8217;ll go back and forth and back and forth&#8230; I am very good at revisiting decisions, and not so good at sticking with a decision I made in the past &#8211; even minutes in the past.</p>

<p>Chris&#8217;s suggestion points out that there are two pieces of information we&#8217;re trying to encode into the name: The idea that passwords have a minimum and maximum valid length, and the specific minimum and maximum (6 and 16 characters). I went with one of those pieces of information, Chris went with the other.</p>

<p>As Chris points out, each style leaves readers to infer something important. With Chris&#8217;s style, readers must infer what&#8217;s special about any given length. With my style, readers must infer what specific lengths form the boundaries. Neither style expresses <em>both</em> pieces of information explicitly &#8211; e.g. that the maximum legal length is 16 characters. There&#8217;s a tradeoff here: Which piece of information to express? And by making that tradeoff differently, each style not only <em>expresses</em> one piece of information, but also <em>emphasizes</em> it. My style emphasizes the idea of minimum and maximum lengths; Chris&#8217;s style emphasizes the specific lengths themselves.</p>

<p>Also, Chris points out (and I agree) that my style requires readers to count string lengths, a tedious, error-prone chore.</p>

<p>Given all of that: <strong>Which style do you prefer? <em>More importantly: What do you prefer about it?</em></strong></p>

<p>Sometimes I can easily see how to trade off possibilities. Other times I can&#8217;t see a clear winner. For those times, I recommend experimenting. Try each possibility. Then pay attention to what happens.</p>

<p>In this case, there&#8217;s another criterion I can apply: With Chris&#8217;s tests, the length of each password appears three times: Once implicitly in the password itself, once in the declaration of the variable, and once in the test that references each variable. Expressing that specific datum three times is potentially troublesome: If we increase the maximum length of a password to 20, we&#8217;d have to change six places (three places for a max length password, three places for a password that&#8217;s too long). With my style, we&#8217;d have to change only two places: the passwords themselves. The variable names would remain the same.</p>

<p>Though I&#8217;m not entirely sure which style emphasizes the more important bit of information, the criterion of &#8220;how many places I&#8217;d have to change&#8221; leaves me preferring the style I used in the article. Chris might still reasonably prefer his style, if the extra expressiveness he perceives is valuable enough to outweigh the extra cost of change.</p>

<p>So far, I still prefer my original variable names to Chris&#8217;s. And yet his suggestion, his thoughtful explanation of why he prefers it, and especially the contrast it provides with my original tests, make me wonder: Now that we know what we&#8217;re trading off, can we find a way to eliminate the tradeoff altogether? Is there another style that allows us to express all of the information we want to express, and without increasing the cost of change?</p>

<p>Uncle Bob, <a href="http://blog.objectmentor.com/articles/2009/12/07/writing-maintainable-automated-acceptance-tests">in his video</a>, offers a third style: Instead of conveying information through variable names, express it through comments. His comments express something similar to my variable names: maximumness and minimumness. It would be easy enough to add the information that Chris&#8217;s variable names express and that mine lack: &#8220;16 characters is just short enough&#8221; and &#8220;6 characters is just long enough&#8221;. I&#8217;ve unfortunately trained myself to feel queasy whenever I start to type a comment into code. I&#8217;m going to have to get over that. Writing a comment is not necessarily evil; it&#8217;s just a tradeoff.</p>

<p>Contrasting my tests to Uncle Bob&#8217;s, I notice yet another tradeoff: How to organize tests into suites? I organized my tests around specific validity criteria: One set of tests for character content requirements, another for length requirements. Uncle Bob organized the same tests differently: One set of tests for valid passwords, another for invalid passwords. And each way of organizing requires us to <em>name</em> our groupings, which offers an opportunity to subtly highlight one piece of information or the other. My organization emphasizes that are two classes of validity criteria, content and length. Uncle Bob&#8217;s emphasizes that passwords may be valid or invalid.</p>

<p><strong>Which emphasis do you prefer? <em>More importantly: What do you prefer about it?</em></strong></p>

<p>A few final points about tradeoffs. If you want to get better at making tradeoffs such as these, step one is to notice what tradeoffs you&#8217;re making. And a great way to do that is to pair with someone. I wrote the tests on my own, and in the article I mentioned the tradeoffs I was aware of making. But I made other tradeoffs implicitly, without noticing I was making them. It was only when Chris and Bob offered alternatives that I noticed I was making those tradeoff at all.</p>

<p>Thanks Chris and Bob for inviting me to explore the tradeoffs I make, and how I make them!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Writing Maintainable Automated Acceptance Tests]]></title>
    <link href="http://cwd.dhemery.com/2009/11/wmaat/"/>
    <updated>2009-11-23T13:33:59-08:00</updated>
    <id>http://cwd.dhemery.com/2009/11/wmaat</id>
    <content type="html"><![CDATA[<p>I&#8217;ve posted &#8221;<a href="http://dhemery.com/pdf/writing_maintainable_automated_acceptance_tests.pdf">Writing Maintainable Automated Acceptance Tes</a>ts&#8221; on my <a href="http://dhemery.com/articles">articles page</a>.</p>

<p>The article demonstrates how to make automated acceptance tests more maintainable by:</p>

<ul>
    <li>Hiding incidental details</li>
    <li>Eliminating duplication</li>
    <li>Naming essential ideas</li>
</ul>


<p>Though the examples in the article use a very nice testing framework called <a href="http://code.google.com/p/robotframework/">Robot Framework</a>, the ideas work just as well with other other popular open-source testing frameworks, such as <a href="http://fitnesse.org/">FitNesse</a> and <a href="http://cukes.info">Cucumber</a>.</p>

<p>You will be able to follow the article even if you don&#8217;t know Robot Framework. But don&#8217;t be surprised if it inspires you to give Robot Framework a try.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Too Much To Ask]]></title>
    <link href="http://cwd.dhemery.com/2009/05/too-much/"/>
    <updated>2009-05-29T07:36:25-07:00</updated>
    <id>http://cwd.dhemery.com/2009/05/too-much</id>
    <content type="html"><![CDATA[<p>Is it too much to ask that people show up to meetings on time? Is it too much to ask that software developers care about craft? Is it too much to ask for an honest politician? Is it too much to ask that drivers drive as if they were sharing the road? Is it too much to ask that immigrants learn how to speak English?</p>

<p>Here’s how to tell whether you’re asking too much: How do you feel when you don&#8217;t get it?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Enthusiasm as a Human Resource]]></title>
    <link href="http://cwd.dhemery.com/2009/04/enthusiasm/"/>
    <updated>2009-04-20T16:35:44-07:00</updated>
    <id>http://cwd.dhemery.com/2009/04/enthusiasm</id>
    <content type="html"><![CDATA[<p>Every so often someone rants about the term “human resources.”  <em>A person is not a resource</em>, they say.  <em>A person is a person.</em>  True enough.</p>

<p>I suppose some managers see people as resources, replaceable, fungible, interchangeable cogs in the corporate machine.  My sense is that few managers who use the term “human resources” use it in that way.  And still the term rankles.</p>

<p>I don’t often use the term myself.  And when I hear it, I interpret it to mean <em>resources that originate in people</em>, in much the same way that natural resources refers not to <em>nature per se</em> as a resource, but to resources that <em>originate</em> in nature.  The human resource is not the person, but something that the person offers to the organization.</p>

<p>Several years ago, Jerry Weinberg offered a nice idea for what that resource is.  I don’t remember Jerry’s exact words, so I’ll paraphrase from my perhaps faulty memory:  <em>The resource is the person’s agreement with the organization.</em>  The resource is the person’s agreement to contribute to organizational ends.</p>

<p>I liked that idea, and I’ve kept it in mind ever since, whenever the “human resource” complaints crop up.</p>

<p>Today I found another idea.  <a href="http://twitter.com/marick/status/1567706398">On Twitter, Brian Marick</a> quoted <a href="http://www.nytimes.com/2009/04/19/magazine/19town-t.html?pagewanted=all">a New York Times article</a> by Jon Mooallem: “[Sandpoint, Idaho council member John] Reuter seemed to argue that enthusiasm is an actual asset, a resource our society is already suffering a scarcity of.”</p>

<p>And my synapses made a connection:  <em>Enthusiasm is the human resource.</em>  Especially in knowledge work, the primary human resource is people’s enthusiasm for the the organization’s purposes and for the work that serves those purposes.</p>

<p>What I like about this notion is that it is more dynamic than “human resource” or even “the person’s agreement.”  A person’s enthusiasm can wax and wane.  We can nurture it, squander it, squash it.  We as leaders have a great deal of influence over how much enthusiasm exists in our organizations, and how much is available for the organization.  And it’s not only renewable, but potentially non-diminishable: We can use people’s enthusiasm in ways that leave them even more enthusiastic than they were before.  And enthusiasm is catching.</p>

<p>By the way, though I’m convinced that distinguishing between management and leadership is an utter waste of time, I’m gonna do it anyway:  A manager deploys people’s enthusiasm toward organizational purposes.  A leader (in an organization) nurtures, cultivates, grows, invites, coaxes, inspires people’s enthusiasm for organizational purposes.</p>

<p>(Yes, I know that enthusiasm is only one thing people offer their organizations, so <em>the</em> human resource doesn&#8217;t tell the whole story.  Of course skills and knowledge matter, too, and a host of other things.  But today I&#8217;m enthusiastic about enthusiasm, so I&#8217;m taking a little blogistic license.)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Anatomy of a Responsibility]]></title>
    <link href="http://cwd.dhemery.com/2009/03/responsibility/"/>
    <updated>2009-03-09T23:06:33-07:00</updated>
    <id>http://cwd.dhemery.com/2009/03/responsibility</id>
    <content type="html"><![CDATA[<p>Because the concept of <strong>system responsibility</strong> is so foundational to how I develop and test software, I want to expand on <a href="http://cwd.dhemery.com/2009/02/planned-response-systems/#responsibility">my earlier description</a>.  Recall that I defined a system responsibility as a system’s obligation to respond to each notification of a specified kind of event under specified circumstances by producing a specified set of planned results.</p>

<p>A system responsibility includes three parts:</p>

<ul>
    <li>A stimulus that triggers the system to respond to an event.</li>
    <li>A context in which the system is required to respond to the stimulus.</li>
    <li>A set of results that the system is obligated to realize in response to that stimulus in that context.
</ul>


<p><a href="http://picasaweb.google.com/lh/photo/585jMgc2tiDWBEY65nsJLw?feat=embedwebsite"><img src="http://lh5.ggpht.com/_4CAMd3shpKw/SbWRWOSXcVI/AAAAAAAAAn4/lBtxMoUn__A/s400/responsibility.jpg" alt="" /></a></p>

<p><strong>Stimulus.</strong> <em>A stimulus is a message, sent by someone or something outside the boundary of the system, that informs the system of an event to which it is obligated to respond.</em> The stimulus has a name, which may identify either the event that it represents or the planned response that the system must carry out.  The stimulus may include additional information about the event.</p>

<p>Stimuli are delivered to a system through its interfaces.  An interface defines a set of messages to which a system responds, and the mechanisms by which those messages are delivered.  For GUI systems, the interface includes a suite of windows, forms, buttons, text fields, and other mechanisms that translate user gestures (mouse clicks, key presses) into messages.  Web-based systems receive stimuli through HTTP requests and other interfaces.  Smaller scale systems, such as objects inside a software application, expose Application Programming Interfaces (APIs) that define the set of methods to which internal objects and subsystems respond.</p>

<p><strong>Result.</strong> <em>A result is an effect that the system realizes in response to a specified stimulus in a specified context.</em> A result may be either a message delivered to someone or something outside the boundary of the system or a change in the system’s internal state.</p>

<p>GUI systems deliver messages through forms, windows, screens, audio devices, and other output devices.  Web-based systems deliver messages through HTTP responses and requests.  An application&#8217;s internal objects and subsystems deliver messages through method calls and method return values.</p>

<p>In addition to delivering messages to external entities, systems also respond to events by recording information internally, and by making changes to that internal information.  The information may be stored inside the running application, in a database, in files on the computer&#8217;s file system, or other storage mechanisms.  The information that a system stores in order to guide its responses to future events makes up the system state.</p>

<p><strong>Context.</strong> Sometimes a system&#8217;s planned response depends not just on information delivered through the stimulus, but other information as well.  <em>The context for a given responsibility is all of the information other than that delivered in the stimulus that influences the results that the system is obligated to realize in response to an event.</em> The context may include information about the state of the system itself&#8211;that is, information that the system previously recorded in its internal memory about prior events.  The context may also include information that the system can observe across its boundary&#8211;information that the system must request from external entities in order to fulfill the responsibility.</ul>
</li>
</ul></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Planned Response Systems]]></title>
    <link href="http://cwd.dhemery.com/2009/02/planned-response-systems/"/>
    <updated>2009-02-19T01:12:14-08:00</updated>
    <id>http://cwd.dhemery.com/2009/02/planned-response-systems</id>
    <content type="html"><![CDATA[<p>I first learned about the idea of planned response systems from III, a colleague and friend of mine.  I later read about the idea in depth in McMenamin and Palmer&#8217;s profound book <em><a href="http://www.amazon.com/exec/obidos/ASIN/0917072308/dalehemery-20">Essential Systems Analysis</a></em>.</p>

<p>The idea of planned response systems is fundamental to how I think about programming and testing.  I&#8217;m posting my thoughts here so that I can refer to these terms and ideas in later blog posts.  Until I write those posts, I encourage you to notice what happens when you think about software systems as planned response systems.</p>

<p>A <strong><a id="prs">planned response system</a></strong> is a system that responds in planned ways to events in its environment.</p>

<p>For example, a software system is a planned response system—it responds in planned ways to users’ actions.</p>

<p>In an object-oriented software systems, each object is a planned response system—it responds in planned ways to messages sent by other objects.</p>

<p>Planned response systems produce two general <strong>kinds of results</strong>: They send messages to entities outside of the system boundary, and they make changes to the essential memory of the system.</p>

<p>An <strong><a id="event">event</a></strong> is a significant change in the system’s environment. A change is <strong>significant</strong> to the system if the system is obligated to respond to the change in a planned way.</p>

<p>Events fall into two broad categories: Changes initiated by entities in the system’s environment (e.g. users or other systems), and temporal events caused by the passage of of time.</p>

<p>For example, an ATM is obligated to respond in a planned way to a user’s request to withdraw cash. The user’s request is an event.</p>

<p>A <strong><a id="responsibility">system responsibility</a></strong> is a system’s obligation to respond to each notification of a specified kind of event under specified circumstances by producing a specified set of planned results.</p>

<p>The specification of a system responsibility consists of three parts: A specification of a kind of event, a specification of a set of circumstances, and a specification of the set of planned results that the system is obligated to produce in response to being notified of an event of that kind under those circumstances.</p>

<p>A system becomes <strong>obligated to respond</strong> to an event when a system designer allocates that responsibility to the system.</p>

<p>The <strong><a id="essence">essence</a></strong> of a planned response system is the set of responsibilities allocated to the system, independent of the choice of technology used to implement the system.</p>

<p>The definition a system’s essence makes no mention whatever of technology inside the system, because the system’s essential responsibilities would be the same whether it were implemented using software, magical fairies, a horde of trained monkeys, or my brothers Glenn and Gregg wielding pencils and stacks of index cards.</p>

<p>One way to identify the essence of a system is to indulge in <strong><a id="fpt">The Fantasy of Perfect Technology</a></strong>. Imagine a system implemented using perfect technology. Then ask yourself some questions about the quality attributes of the system.</p>

<p>How fast would it respond? <em>If it were made of perfect technology, of course it would respond instantly, with zero delay.</em> How many users could use it at once? <em>An infinite number of users.</em> How much information could it store? <em>An infinite amount.</em> How often would it break? <em>It would never break.</em> How long does it take to start up? <em>None, because it’s always on and always available.</em> How much energy would it use? <em>It would use no energy; heck, it might even generate energy for free.</em></p>

<p>The one glaring flaw of perfect technology is that it does not exist. Real-world technology is imperfect. That’s what makes this exercise a fantasy. But it’s a useful fantasy, because it helps us to separate the system’s essential responsibilities from the temporary constraints of current technology.</p>

<p>Note that we apply the Fantasy of Perfect Technology only inside the boundary of the system. Even in our fantasy, the world outside of the system is made of real, imperfect stuff, with which the system will have to interact.</p>

<p>Now apply the fantasy to your own system. What responsibilities would your system have even if you could implement it using perfect technology? That set of responsibilities is your system’s essence.</p>

<p>The <em>essential memory</em> of a system is the set of data that the system must remember in order to fulfill its obligations—that is, in order to respond as planned to future events.</p>

<p>For example, an ATM must remember users’ account balances in order to determine whether to satisfy users’ requests to withdraw money.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Beware Accounting Errors]]></title>
    <link href="http://cwd.dhemery.com/2008/12/accounting/"/>
    <updated>2008-12-31T13:06:21-08:00</updated>
    <id>http://cwd.dhemery.com/2008/12/accounting</id>
    <content type="html"><![CDATA[<p>Beware accounting errors.</p>

<p>A highly visible part of TDD is that developers write more tests than they used to.  It is tempting to conclude from this that programming takes longer with TDD than without.  After all, we are writing tests that we didn’t write before, and this is additional work on top of all the work we used to do.  Right?</p>

<p>That’s a perfectly reasonable conclusion.  But it is based on a flawed assumption, an accounting error that leads us to overlook some important costs.  The assumption is that in addition to the new work of writing tests, developers will continue to do all of the same work they were doing before.</p>

<p>This assumption turns out to be unwarranted in practice.  For example, before TDD, developers typically spend a great deal of time debugging.  Why are they debugging?  Because they have identified a failure, but they don’t know what specific piece of code is broken that produces the failure.  They step through the code in the debugger in order to trace the failure to the fault.  Only when they identify the broken code can they fix it.</p>

<p>TDD reduces the amount of debugging in two ways.  First, developers write fewer defects.  Second, when a developer introduces a defect, the code immediately fails one or more tests.  These tests point directly toward the broken code.  If the tests tell me what specific code is broken, I don’t need to run the debugger to find the fault.</p>

<p>Also, if developers write fewer defects, they now spend less time fixing defects.</p>

<p>If we add up all of the effects of TDD, including the cost of writing tests and the cost savings we gain by writing tests, we find that the first few features cost slightly more than without TDD, but that the quality is noticeably higher.  And we find that later features take less time than without TDD, because TDD keeps code changeable.</p>

<p>An additional wrinkle leads to another accounting error: not everyone sees debugging as a cost.  In my pre-TDD days, I usually enjoyed debugging.  I loved having a meaty puzzle to solve.  It was often the most fun and interesting and engaging part of programming.  And in one job, my managers (falling prey to yet another accounting error) rewarded <em>fixing</em> bugs far more visibly and vocally than <em>preventing</em> them.</p>

<p>If you&#8217;re a manager, learn to attend not just to the obvious costs and benefits of a given set of programming practices, but also the costs and benefits that require a little effort and insight to detect.</p>

<p>If you&#8217;re a developer, I can tell you that I don&#8217;t miss debugging.  The puzzle of how to choose the next test that will drive my code toward completion is as fun and interesting and challenging as debugging ever was.  I hope it&#8217;s the same for you.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Testing is an Information Service]]></title>
    <link href="http://cwd.dhemery.com/2008/12/information-service/"/>
    <updated>2008-12-30T15:37:11-08:00</updated>
    <id>http://cwd.dhemery.com/2008/12/information-service</id>
    <content type="html"><![CDATA[<p><strong>Testing is an information service.</strong>  The point of testing is to inform stakeholders about the system.  This is not a new sentiment, nor does it originate with me.  But I&#8217;ve found that many testers have not considered their role from this perspective.</p>

<p>I teach classes about how to test software.  Early in each class I describe testing as an information service.  Even in classes filled with experienced testers, there are always a few people for whom this is a new idea.</p>

<p>In one class, just as I finished saying that testing is an information service, a man in the back of the room said, &#8220;Oh, no!&#8221;</p>

<p>&#8220;You disagree?&#8221; I asked.</p>

<p>&#8220;No, no, I agree,&#8221; he said.  &#8220;It&#8217;s just that I&#8217;ve never thought of it that way before.&#8221;  He paused and frowned.  &#8220;And I think I&#8217;ve been doing it all wrong.&#8221;</p>

<p>I thought it was unlikely that he&#8217;d been doing it <em>all</em> wrong, so I asked, &#8220;How have you been doing it?&#8221;</p>

<p>&#8220;I just try to break stuff.  When I can break it, it&#8217;s like I win.  And if I can&#8217;t break it, I feel like I&#8217;m failing.&#8221;</p>

<p>&#8220;Trying to break stuff,&#8221; I said, &#8220;is an important part of testing.&#8221;  I mentioned James A. Whittaker&#8217;s excellent book <em><a href="http://www.amazon.com/exec/obidos/ASIN/0201796198/dalehemery-20">How to Break Software</a></em>, which teaches testers how to find the kinds of defects that arise from common programming errors.</p>

<p>&#8220;I know,&#8221; he said, &#8220;but that&#8217;s <em>all</em> I&#8217;ve been doing.  And when I find a nice, nasty bug, I run over to the developers and rub it in their faces.&#8221;</p>

<p>&#8220;Oh, no&#8221;, I said.</p>

<p>He laughed and nodded.  &#8220;Now you understand.&#8221;</p>

<p>&#8220;How does that work out?&#8221; I asked.  (I know what you&#8217;re thinking, but you&#8217;ve got it backwards.  Doctor Phil channels <em>me</em>.)</p>

<p>&#8220;They hate it.  And hate to see me coming.  They keep telling me to bring them some <em>good</em> news once in a while.&#8221;</p>

<p>&#8220;But if your job is only to break stuff&#8230;&#8221;</p>

<p>&#8220;Then I never tell them what&#8217;s working.  But that&#8217;s information, too, and that&#8217;s what I just realized.  And that&#8217;s what they&#8217;ve been asking for.&#8221;</p>

<p>I&#8217;ve had numerous similar conversations with testers who had found themselves mired in unproductive relationships with developers.  Shifting your focus from breaking stuff to informing stakeholders (including developers) can help with that.</p>

<p>I&#8217;ll say more later about testing as an information service.  In the meantime, I&#8217;d love to hear your questions and comments about it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Interviewing Characters: Follow the Energy]]></title>
    <link href="http://cwd.dhemery.com/2008/09/interviews/"/>
    <updated>2008-09-10T21:22:27-07:00</updated>
    <id>http://cwd.dhemery.com/2008/09/interviews</id>
    <content type="html"><![CDATA[<p>On November 13, 2007 I ran out of plot for the NaNoWriMo novel I was writing.  I had no idea what to write next.  That&#8217;s not uncommon for NaNo novelists, but I hadda do something to jiggle myself loose.  In NaNoWriMo, word count is everything, and I couldn&#8217;t afford to fall behind.</p>

<p>So I tried something I hadn&#8217;t tried before:  I interviewed my characters.</p>

<p>Well, that turned out to be more interesting than I&#8217;d anticipated.  And it boosted my word count to boot.  And on top of that, it offered some plot ideas.</p>

<p>I didn&#8217;t use any pre-planned questionnaire.  There are zillions of character questionnaires on the web, and none of them ever seemed to get at the heart of the character.</p>

<p>Instead, I did what I do in many real-life interviews:  Follow the energy.  The idea is to:</p>

<ol>
<li>Ask a question that invites the character to tell me something new</li>
<li>Listen for emotional intensity in the answer.  Sometimes the emotion is subtle, and other times it&#8217;s big and obvious.</li>
<li>Ask my next question based on that emotion.</li>
</ol>


<p>Rather than describing this process in detail, I&#8217;ll let you read the interviews as I conducted them, unedited.  I offer these interviews not necessarily as exemplary, but merely as examples.  The thing to notice is how I followed the characters&#8217; energy.</p>

<p>Some background:  The novel involves a time loop.  Every 29 hours, the characters (and everyone else in the story world) loop back in time.  The story follows two main plots.</p>

<p>In the first plot, Dan Roberge murders his wife Faith and her lover Zorem.  Then time loops and he murders them again.  And again.  Police detectives Ray Andollo and Patty Yonce investigate.</p>

<p>The interviews:</p>

<ul>
<li><a href="http://dalefiction.dale.emery.name/2007/11/mhr-int-dan/">Dan Roberge</a></li>
<li><a href="http://dalefiction.dale.emery.name/2007/11/mhr-int-faith/">Faith Roberge</a></li>
<li><a href="http://dalefiction.dale.emery.name/2007/11/mhr-int-zorem/">Zorem Bigotte</a></li>
<li>Detective <a href="http://dalefiction.dale.emery.name/2007/11/mhr-int-ray/">Ray Andollo</a></li>
<li>Detective <a href="http://dalefiction.dale.emery.name/2007/11/mhr-int-patty/">Patty Yonce</a></li>
</ul>


<p>In the second plot, Amy Anderson saves her son from drowning in a pond on the family farm.  Then time loops and her son drowns.  Then time loops again.  After the first incident (before the first time loop), Amy&#8217;s husband Frank becomes engraged when he discovers that Amy had been drinking while their sons played at the pond.</p>

<p>The interviews:</p>

<ul>
<li><a href="http://dalefiction.dale.emery.name/2007/11/mhr-int-amy/">Amy Anderson</a>.  This was my favorite interview, because it so significantly affected my understanding of the character.</li>
<li><a href="http://dalefiction.dale.emery.name/2007/11/mhr-int-frank/">Frank Anderson</a></li>
</ul>

]]></content>
  </entry>
  
</feed>

