<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ryan norris &#187; agile</title>
	<atom:link href="http://www.ryannorris.com/tag/agile/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryannorris.com</link>
	<description>managing software teams and delivering great results</description>
	<lastBuildDate>Fri, 25 Jun 2010 13:44:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The Baseball Manager and Agile:  How America&#8217;s Game Forces It&#8217;s Decision Makers to Be Responsive</title>
		<link>http://www.ryannorris.com/2010/03/22/the-baseball-manager-and-agile-how-americas-game-forces-its-decision-makers-to-be-responsive/</link>
		<comments>http://www.ryannorris.com/2010/03/22/the-baseball-manager-and-agile-how-americas-game-forces-its-decision-makers-to-be-responsive/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 02:41:05 +0000</pubDate>
		<dc:creator>Ryan Norris</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[scrum]]></category>
		<category><![CDATA[baseball]]></category>

		<guid isPermaLink="false">http://www.ryannorris.com/?p=164</guid>
		<description><![CDATA[Among the various extra-curriculars that take up my downtime, baseball is up there.  Baseball was a passion for much of my youth.  As I got older and my attention turned towards my career and the world at large, the dawn of Michael Lewis&#8217; &#8220;Moneyball&#8221; changed my view on baseball entirely.  Baseball became, for better or [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Among the various extra-curriculars that take up my downtime, baseball</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">is up there.  Baseball was a passion for much of my youth.  As I got older and my attention turned towards my career and the world at large, the dawn of Michael Lewis&#8217; &#8220;Moneyball&#8221; changed my view on baseball entirely.  Baseball became, for better or for worse &#8211; less interesting to watch for 180 days a year and more intrigiung to capture in the snapshots of statistics and numbers that engulfed baseball in the early 2000&#8242;s.  Lewis was demonstrating not a new approach to how baseball was played, but how Oakland A&#8217;s manager Billy Beane was simpy exploiting an efficiency that none of his contemporaries had (yet) uncovered.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">So recently I found myself thinking about the role of the manager in baseball.  As other teams began looking at the Oakland model for constructing successful, cost-conscious rosters, many copied their formula.  Others began to look for other efficiencies.  But the manager role &#8211; the ultimate &#8220;chicken&#8221; contrasted to the players as pigs, has only had cursory evalution for their affect on the outcome of the game.  These evaluations are subjective by and large, and have all concluded in one way or form that managers tend to have zero net effect on the success or failure of a team.  But baseball managers are perhaps one of the most agile practitioners today.  They must be responsive, they must have enough foresight to plan only enough in that they can mitigate risk, but not so much as to commit themselves to a shortsighted approach.  Their sprints are innings, their releases are games.  They create ample time to adjust and replan.  They are agile creatures &#8211; perhaps the original agile management style.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Every Game is a Release</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Before every game, the manager has a plan to build.  The lineup is first and foremost.  It ultimately has very little affect on the outcome of the game, provided that the manager has planned for his best hitters to be part of the game.  Additionally and potentially irrelevant statistically &#8211; the manager will prioritize his lineup which will offer the most potential value for that game.  The catcher amy be different depending on his own starting pitcher.  Lefthanded hitters, statistically vulnerable to left-handed pitching may sit on the bench to start the game while statistically inferior players fill-in for the handicapped lefthander.  Some players may be removed from the roster entirely, optioned to a monior league affiliate to allow for superior options to be available in the case the need arises.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The analogy here, is release planning.  Just like the manager has an assortment of players, we have a backlog.  Each story offers value that may change from one sprint to the next.  Each story may shuffle in priority from one sprint to the next.  But the focus is always on ensuring that during a release we are planning to ensure that we are successful in every area of our sprints during the release while aiming to maximize the success of our teams over the entirety of the release.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Every Inning is a Sprint</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Baseball is a strange game in that every inning, the defense controls the ball.  There are 9 innings in a game, and 3 outs per inning.  These are our resources.  As a manager, my job is to allow my team to execute while intervening only when resource mismanagement is certain.  I may pinch hit for a hitter in order to maximize run production while minimizing outs.  Conversely, I may change pitchers frequently to ensure my competition is least able to use their resources to their fullest.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Managing sprints is a task in managing your resources optimally.  Each sprint we start with our planning meeting where we identify what resources are available for the current sprint.  Then, based on various factors &#8211; we figure in what we can get done during the sprint.  How we get there may change, but the goal is always part of a theme.  In baseball, this is a touch of a stretch &#8211; but it&#8217;s hard to think that a manager going into the 9th down by 3 isn&#8217;t planning his decisions on maximizing on-base percentage that inning with the prospect of his best power hitter in the dugout.  Often times when a team hasn&#8217;t scored the tying or lead run but is threatening to score, the bullpen will warm up, a proactive response to something which may not be certain.  A lot of baseball management is about thinking foreward just far enough to be prepared for what you know is next and not focusing too much on the possibilities in September while it&#8217;s still May.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Baseball Teams Are Self-Managing</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">This is more hypothetically true than true in reality.  It&#8217;s not unheard of for players to be managers as well.  But unlike professional American football where the level of specialization and differentiation between offensive and defensive roles is stark, or professional basketball where the players can succeed independently of the team, even if the team fails &#8211; baseball players are incredibly independent in their affect on any given contest.  While Michael Jordan and Kobe Bryant may have singlehandedly one NBA titles for their respective teams, Derek Jeter and Curt Schilling would have not won their rings were it not for the complimentary (but not cooperative) talents of the players that surround them.  They exhibit classic examples of game theory where the benefits of the strength of their performance are best realized by them only when realized by all.  That is a key trait of the self-organizing team.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">What Baseball Can Tell Us About Software</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">While these two things are markedly different, baseball managers and players are clear examples of self-sufficient and practical agile applications.  Managers aim to minimize risk and maximize prdocution while only planning for the factors that are at hand or probable rather thah trying to account for any possible scenario.  This is not too indifferent from how a ScrumMaster must operate.  If baseball managers went into game 1 concerned about game 60, they would be accused of guesswork and incompetence.  Uncertainty would doom their plan, the pundits would not.  This is not at all indifferent from Agile software teams that learn from recent results and apply the lessons from the most recent experiences immediately.</div>
<p>Among the various extra-curriculars that take up my downtime, baseball is up there.  Baseball was a passion for much of my youth.  As I got older and my attention turned towards my career and the world at large, the dawn of Michael Lewis&#8217; &#8220;Moneyball&#8221; changed my view on baseball entirely.  Baseball became, for better or for worse &#8211; less interesting to watch for 180 days a year and more intriguing to capture in the snapshots of statistics and numbers that engulfed baseball in the early 2000&#8242;s.  Lewis was demonstrating not a new approach to how baseball was played, but how Oakland A&#8217;s manager Billy Beane was simply exploiting an efficiency that none of his contemporaries had (yet) uncovered.</p>
<p>So recently I found myself thinking about the role of the manager in baseball.  As other teams began looking at the Oakland model for constructing successful, cost-conscious rosters, many copied their formula.  Others began to look for other efficiencies.  But the manager role &#8211; the ultimate &#8220;chicken&#8221; contrasted to the players as pigs, has only had cursory evaluation for their affect on the outcome of the game.  These evaluations are subjective by and large, and have all concluded in one way or form that managers tend to have zero net effect on the success or failure of a team.  But baseball managers are perhaps one of the most agile practitioners today.  They must be responsive, they must have enough foresight to plan only enough in that they can mitigate risk, but not so much as to commit themselves to a shortsighted approach.  Their sprints are innings, their releases are games.  They create ample time to adjust and re-plan.  They are agile creatures &#8211; perhaps the original agile management style.</p>
<p><span id="more-164"></span></p>
<p><strong>Every Game is a Release</strong></p>
<p>Before every game, the manager has a plan to build.  The lineup is first and foremost.  It ultimately has very little affect on the outcome of the game, provided that the manager has planned for his best hitters to be part of the game.  Additionally and potentially irrelevant statistically &#8211; the manager will prioritize his lineup which will offer the most potential value for that game.  The catcher amy be different depending on his own starting pitcher.  Lefthanded hitters, statistically vulnerable to left-handed pitching may sit on the bench to start the game while statistically inferior players fill-in for the handicapped lefthander.  Some players may be removed from the roster entirely, optioned to a minor league affiliate to allow for superior options to be available in the case the need arises.</p>
<p>The analogy here, is release planning.  Just like the manager has an assortment of players, we have a backlog.  Each story offers value that may change from one sprint to the next.  Each story may shuffle in priority from one sprint to the next.  But the focus is always on ensuring that during a release we are planning to ensure that we are successful in every area of our sprints during the release while aiming to maximize the success of our teams over the entirety of the release.</p>
<p><strong>Every Inning is a Sprint</strong></p>
<p>Baseball is a strange game in that every inning, the defense controls the ball.  There are 9 innings in a game, and 3 outs per inning.  These are our resources.  As a manager, my job is to allow my team to execute while intervening only when resource mismanagement is certain.  I may pinch hit for a hitter in order to maximize run production while minimizing outs.  Conversely, I may change pitchers frequently to ensure my competition is least able to use their resources to their fullest.</p>
<p>Managing sprints is a task in managing your resources optimally.  Each sprint we start with our planning meeting where we identify what resources are available for the current sprint.  Then, based on various factors &#8211; we figure in what we can get done during the sprint.  How we get there may change, but the goal is always part of a theme.  In baseball, this is a touch of a stretch &#8211; but it&#8217;s hard to think that a manager going into the 9th down by 3 isn&#8217;t planning his decisions on maximizing on-base percentage that inning with the prospect of his best power hitter in the dugout.  Often times when a team hasn&#8217;t scored the tying or lead run but is threatening to score, the bullpen will warm up, a proactive response to something which may not be certain.  A lot of baseball management is about thinking forward just far enough to be prepared for what you know is next and not focusing too much on the possibilities in September while it&#8217;s still May.</p>
<p><strong>Baseball Teams Are Self-Managing</strong></p>
<p>This is more hypothetically true than true in reality.  It&#8217;s not unheard of for players to be managers as well.  But unlike professional American football where the level of specialization and differentiation between offensive and defensive roles is stark, or professional basketball where the players can succeed independently of the team, even if the team fails &#8211; baseball players are incredibly independent in their affect on any given contest.  While Michael Jordan and Kobe Bryant may have single handedly one NBA titles for their respective teams, Derek Jeter and Curt Schilling would have not won their rings were it not for the complimentary (but not cooperative) talents of the players that surround them.  They exhibit classic examples of game theory where the benefits of the strength of their performance are best realized by them only when realized by all.  That is a key trait of the self-organizing team.</p>
<p><strong>What Baseball Can Tell Us About Software</strong></p>
<p>While these two things are markedly different, baseball managers and players are clear examples of self-sufficient and practical agile applications.  Managers aim to minimize risk and maximize production while only planning for the factors that are at hand or probable rather than trying to account for any possible scenario.  This is not too indifferent from how a Scrum-Master must operate.  If baseball managers went into game 1 concerned about game 60, they would be accused of guesswork and incompetence.  Uncertainty would doom their plan, the pundits would not.  This is not at all indifferent from Agile software teams that learn from recent results and apply the lessons from the most recent experiences immediately.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannorris.com/2010/03/22/the-baseball-manager-and-agile-how-americas-game-forces-its-decision-makers-to-be-responsive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Your QA Staff with Engineering in SCRUM</title>
		<link>http://www.ryannorris.com/2009/08/14/integrating-your-qa-staff-with-engineering-in-scrum/</link>
		<comments>http://www.ryannorris.com/2009/08/14/integrating-your-qa-staff-with-engineering-in-scrum/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 11:53:24 +0000</pubDate>
		<dc:creator>Ryan Norris</dc:creator>
				<category><![CDATA[Project Teams]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[scrum]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[beck]]></category>
		<category><![CDATA[delivery]]></category>
		<category><![CDATA[fowler]]></category>
		<category><![CDATA[qa]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.ryannorris.com/?p=88</guid>
		<description><![CDATA[As much as I love automated testing, I have come to live with the fact that teams migrating from waterfall approaches to development to SCRUM often try to maintain the team structures they are familiar with.  At times, this typically means an engineering staff that sucks at writing tests, and a QA staff that is [...]]]></description>
			<content:encoded><![CDATA[<p>As much as I love automated testing, I have come to live with the fact that teams migrating from waterfall approaches to development to SCRUM often try to maintain the team structures they are familiar with.  At times, this typically means an engineering staff that sucks at writing tests, and a QA staff that is still very much attuned to the finer grained edge and corner cases.  Each of these parts of your team adds value to a SCRUM project.  Integrating them to avoid bottlenecks, stay lean, and deliver with quality is a clever trick.</p>
<p><span id="more-88"></span>Engineers write code.  QA tests that code.  In the past, this baton model has been derived from extensive functional specifications and use case documents that break down the core, extension, and exception cases so that both the tests and software can be clearly defined.  In a waterfall model, this was functional as it mirrored the sequence of SDLC.  But SCRUM and most Agile processes really shun this kind of thinking and instead target flat teams that collectively own the deliverable.  As in a recent experience of mine, maintaining that same handoff creates all sorts of problems.  Acceptance and rejection of delivered stories occurs late in the game, QA is always in a rush to execute their tests, and product teams and development see QA as a bottleneck.  It&#8217;s tempting for management to look at this and begin to turn SCRUM into a series of miniature waterfalls.  But this is <strong>wrong.</strong> Instead, as with all things in SCRUM, the search for a solution needs to answer a few questions to make the possible actions palatable:</p>
<ol>
<li>Will the solution eliminate dependencies my team has?</li>
<li>Does this solution change the value that one set of skills adds to my team, or does it distribute it?</li>
<li>Will this solution be responsive to change?</li>
<li>Will this solution require extensive infrastructure to implement?</li>
</ol>
<p>Heroes <a title="Kent Beck" href="http://www.threeriversinstitute.org" target="_blank">Kent Beck</a> and <a title="Martin Fowler" href="http://www.martinfowler.org" target="_blank">Martin Fowler</a> will tell you that the best solution is to strive for full, automated testing.  I couldn&#8217;t agree more.  Manual testing, as Fowler recently said, should be considered &#8220;a human rights violation.&#8221;  It&#8217;s error prone, difficult to repeat, and handles regression poorly.  That said, there are some battles simply not worth fighting.  In larger, more established teams &#8211; this type of shift is glacial, largely because of the risk incurred by such a change in paradigm.  Pragmatism dictates that the value of your QA team be repurposed to continue to add value, though potentially in a different way.</p>
<p>If we can concede the anecdotal thought that most engineers are substandard at QA, then we can see a glaring gap on a SCRUM team.  Even full automated testing with xUnits and CI is going to relinquish some level of code coverage, particularly in legacy software that wasn&#8217;t designed to be tested 10 years ago.  It should be mandated in teams in this type of pickle that all future code adopt the best practices of TDD &#8211; even to the extent that older, less TDD-friendly technologies and architectures be phased out.  But as we engage a group of engineers in a methodology in which they may never have been educated, hired, or trained for &#8211; on the sidelines we have a group of people who have been identifying failure and success scenarios their entire careers &#8211; even if they aren&#8217;t engineers.  A QA team can be indispensible in this situation.</p>
<p>In your new, SCRUM-based project &#8211; QA no longer are the gatekeepers.  We can&#8217;t have multiple gatekeepers in SCRUM.  Instead we focus on delivery and acceptance, creating one gatekeeper &#8211; a single keeper of the truth: the product owner.  That role is intended to be their exclusive domain.  They are the most intimate with the domain, the most intimate with the user story, and the most knowledgeable of where value lies.  To vest these judgmental by proxy in a serial part of the development cycle only leads to confusion.  Who is really assessing value?  Who is ultimately going to decide whether or not a story can be delivered?  Who should decide whether it should be accepted?  The demographics of a SCRUM project exist to solve this very question.  Eroding the clarity of role simply detracts value.</p>
<p>So what does this mean?  QA can&#8217;t be relegated to the role of testing system.  They cannot be an analogue for some sort of software framework.  Our goal should be to migrate to full automation, even if that takes time.  This means that the role of QA changes to an engineering role.  Not in the software sense, but in developing the cases which need to be tested.  These will arise from:</p>
<ol>
<li>Conversational contributions to the story, noting and documenting constraints by guiding the product owner through different user experiences.  These can come out of user flows or non-functional prototypes.  But QA can add extensive value simply by contributing their ability to identify edge and corner cases that may not have been considered.  These may well not end up in our <em>confirmation</em> of the story, and it&#8217;s important for QA to recognize, just like with an engineer &#8211; that the value of a contribution in the conversation is to help shape the conversation, and not set requirements in the stead of the product owner.</li>
<li>Test cases derived from the constraints outlined in the conversation.  Take this user story:
<p><em>A user must be able to provide a credit card for payment of their order.  Each credit card must be validated with the issuer, and we will only accept credit cards from Visa and MasterCard.</p>
<p>Try it with Discover card.<br />
Try it with American Express.<br />
Try it with an invalid billing address.</p>
<p></em>This is the way that the product owner will ultimately accept the story.  The QA resource working on this story may write several test cases that test the edge and corner cases of the acceptance criteria, but they need to maintain an open conversation with the team to ensure they aren&#8217;t incidentally increasing scope by applying tests that go outside of the criteria.  So while the following test case is very likely to be something we&#8217;ll want to test:</p>
<p><em>Try a billing address where the street name is provided in all capital letters but matches the address on file which is entirely in lower case.  This is expected to be a positive case, with the validation succeeding.</p>
<p></em>This test would likely be considered an expansion of scope or otherwise invalid:</p>
<p><em>Try charging the card and ensure that we put a $5 hold on the card until the transaction is complete.</em></li>
</ol>
<p>So, in the cycle of the development of the story, the test cases serve as the outline for the engineer &#8211; as they should.  The engineer uses the tests to validate their code &#8211; or more effectively, runs their code against an automated test that implements the test case as defined by the QA specialist.  This helps improve quality and minimize risk by taking those decisions which we earlier agreed that engineers are poor at, out of their hands.  The test cases serve now as the same direction that the rest of the story does.  For those tests which remain manual for whatever reason, the effort to complete those tests can now be load balanced across the team, rather than vested in the hands of one point of failure in delivery.</p>
<p>Ultimately, this is what is so enjoyable about an Agile project.  Because it suggests solutions through it&#8217;s objectives, it&#8217;s possible to solve any execution concern by referring back to the principles that make Agile delivery successful.  Being able to respond to change, emphasize people and interactions, and prefer generalization over specialization is the guidance we can use to look at the role of the heroic QA team in a different light &#8211; a somewhat specialized engineering team that delivers artifacts that infuse delivery with the value that it may not be realizing in engineering, and not acting as a secondary source of truth for the team.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannorris.com/2009/08/14/integrating-your-qa-staff-with-engineering-in-scrum/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An Omniscient Learning Approach to Mock-based TDD</title>
		<link>http://www.ryannorris.com/2009/04/16/an-omniscient-learning-approach-to-mock-based-tdd/</link>
		<comments>http://www.ryannorris.com/2009/04/16/an-omniscient-learning-approach-to-mock-based-tdd/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 03:29:31 +0000</pubDate>
		<dc:creator>Ryan Norris</dc:creator>
				<category><![CDATA[Building Better Software]]></category>
		<category><![CDATA[Enterprise Architecture]]></category>
		<category><![CDATA[Java Development]]></category>
		<category><![CDATA[Services as Software]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.ryannorris.com/?p=69</guid>
		<description><![CDATA[I recently posted about why I think mocks are simply the easiest way to get the most bang for your buck in automated software testing.  But integrating it as part of a process is hard, and teaching it is even harder.  Young developers seem to have a hard time grasping the idea of testing isolated [...]]]></description>
			<content:encoded><![CDATA[<p>I recently posted about why I think mocks are simply the easiest way to get the most bang for your buck in automated software testing.  But integrating it as part of a process is hard, and teaching it is even harder.  Young developers seem to have a hard time grasping the idea of testing isolated units of code.  I&#8217;ll confess &#8211; for a long time, much of my unit testing involved setting up the appropriate test environments &#8211; Spring containers for persistence units, test databases, you name it.  It&#8217;s expensive to test this way, and there are only so many situations when integration tests are valuable.  On lean, agile teams &#8211; code coverage isn&#8217;t held in as high regard as having working software.  On lean, agile teams &#8211; tests are a driver towards design, but they do need to be rooted in some level of initial thought on how a problem needs to be solved.</p>
<p><span id="more-69"></span></p>
<p>So understanding how a unit test is traceable back to a technical design on an agile team is really a key differentiation between an approach that more closely resembles cowboy coding and an approach which is relatively holistic.  No scrum master, project manager, or even architect would advocate full designs in an agile environment &#8211; instead we opt for lighter weight approaches to technical design that provide a blueprint to the code.  For many teams, this is a CRC card &#8211; a simply way of documenting the various dimensions of an object-oriented unit.</p>
<p>What is a CRC, and how does it relate back to tests?</p>
<p><strong>Class</strong></p>
<p>The core unit of code that we will refer to is the class, but this can be really any aggregation &#8211; a function library even.  This represents a loose collection of related functionality that leverages common resources, represents a concept of actions or identity, or extends existing functionality.</p>
<p><strong>Responsibilities</strong></p>
<p>The responsibilities of the class form it&#8217;s <em>raison d&#8217;etre. </em>Commonly, we can analogize responsibilities with methods, but they may be more coarse grained &#8211; and our refactoring may indeed refine the level of detail with which we understand the functional responsibilities of the class.</p>
<p><strong>Collaborators</strong></p>
<p>From an interestingness perspective, particularly in the context of unit testing and mocking (or stubbing), collaborators really take the cake.  When we talk about <em>dependency injection</em> as the core pattern of test-driven development with mocks, collaborators are indeed what we are injecting into our class to power it.</p>
<p>I always ask my green developers to think about these things before starting any sort of development.  Once their CRC is done and we agree on the approach, I ask them to build the programming interface, stub the implementation, and then start writing tests.  A common example I like to use when I get that befuddled look is the idea of a car.  A car has a lot of complex stuff going on that if I needed to test dependent functions of the car against, I wouldn&#8217;t want to have to concoct all of the function they provide.  For instance, the engine is a complex piece of machinery &#8211; but if I solely want to to test how my transmission reacts to engine behavior &#8211; it&#8217;s the transmission class I want to ultimately test, and it&#8217;s reactions to different engine behavior.</p>
<p>Let&#8217;s bring it up a level and talk about a Car as the core class.  We want our car to be able to do two things &#8211; to have two <em>responsibilities</em>: accelerate and stop.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Car <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">int</span> accelerate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> additionalVelocity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">void</span> setTireGrip<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> gripFactor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">int</span> stop<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> overDistance<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> CannotStopException<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Motorable <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">int</span> injectGasoline<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> mlOfFuel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Stoppable <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">int</span> applyBrakes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> PadException, RotorException, WetRoadException<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So we&#8217;ve defined 3 interfaces.  Let&#8217;s say that I&#8217;m really interested in a case where I test how the car reacts to different stopping conditions.  Now, I&#8217;m demonstrating this in Java, so I&#8217;ll use syntax similar to Mockito &#8211; but the rules are the same:  I&#8217;m interested in testing the requirements of the car <em>observing the expected behavior of the brakes in those conditions</em>.  When the grip is set low, we expect the braking system to respond negatively and lock up.</p>
<p>We&#8217;ll also assume for now that I&#8217;ve stubbed out a skeletal implementation of the Car interface (meaning that everything throws a NotImplementedException for the time being).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Test
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testWetRoadConditionsWithLowFriction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// arrange</span>
   Stoppable s <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Stoppable.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   Motorable m <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Motorable.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   Car c <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CarImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   c.<span style="color: #006633;">setStopAbility</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   c.<span style="color: #006633;">setMotor</span><span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   c.<span style="color: #006633;">setGripFactor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   when<span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">applyBrakes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenThrow</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> WetRoadException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// act and assert - no real assertion, we're expecting an exception</span>
      c.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Should have seen a CannotStopException - there's not a lot of grip for road when road conditions are wet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>CannotStopException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// do nothing, we're a success!</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, we&#8217;re not actually testing the brakes &#8211; we&#8217;re testing that under the given conditions that when the Stoppable interface throws an exception that prevents our car from stopping successfully that we are throw our own CannotStopException in response.  The stoppable interface is a <em>collaborator</em>; we are not interested in this case in unit testing it, we are interested in asuming a known behavior from it, and testing how the stop() ability of the Car implementation reacts to the WetRoadException that we have stubbed.</p>
<p>The alternative in the past would have been to actually create the implementation of Stoppable.  But having to unit test both items makes it difficult to isolate implementation issues.</p>
<p>So ultimately young developers, your unit tests need to test a single responsibility and not the responsibility of your collaborators.  You may eventually test how the two implementations interact &#8211; that is an integration test.  Ultimately though, there is more value in testing each individual unit and ensuring that the code is built to the spec of your lightweight design.  Then you can isolate integration issues and write tests that specifically address finding integration problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannorris.com/2009/04/16/an-omniscient-learning-approach-to-mock-based-tdd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocks &#8211; the only thing separating complex TDD from value-added TDD</title>
		<link>http://www.ryannorris.com/2009/04/08/mocks-the-only-thing-separating-complex-tdd-from-value-added-tdd/</link>
		<comments>http://www.ryannorris.com/2009/04/08/mocks-the-only-thing-separating-complex-tdd-from-value-added-tdd/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 03:18:05 +0000</pubDate>
		<dc:creator>Ryan Norris</dc:creator>
				<category><![CDATA[Building Better Software]]></category>
		<category><![CDATA[Enterprise Architecture]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[integration testing]]></category>
		<category><![CDATA[mockito]]></category>
		<category><![CDATA[rhinomocks]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.ryannorris.com/?p=64</guid>
		<description><![CDATA[About two years back when I started getting completely fascist about test-driven development, the complexity was always &#8220;gee, i have an application container and I need to involve it in my unit tests so that I can get full test coverage !!111oneeleventy.&#8221; This typically meant providing a real collaborator, like a PersistenceUnit in Java, so [...]]]></description>
			<content:encoded><![CDATA[<p>About two years back when I started getting completely fascist about test-driven development, the complexity was always &#8220;gee, i have an application container and I need to involve it in my unit tests so that I can get full test coverage !!111oneeleventy.&#8221;</p>
<p>This typically meant providing a real <em>collaborator</em>, like a PersistenceUnit in Java, so that I could test trivial operations like persisting an entity.  At the time, I challenged a manager on this:</p>
<p><em>What are we really testing?  Are we testing OUR requirement, or are we testing something we should reasonably expect Hibernate to do on the basis of our initial technology selection?</em></p>
<p>Code coverage I believe is pretty overrated.  No one cares whether or not you can prove your method to persist an entity works <strong>because the developers of Hibernate/TopLink/LINQ to SQL have already proved this through their unit tests. </strong>What you are building when you write a test that actually checks the database to see if <em>your middleware </em>used a pre-packaged <em>object-relational manpping framework</em> correctly is an integration test.  There&#8217;s certainly value to integration testing with data access layers, particularly when difficult to test components of your middleware (like stored procedures and triggers) are involved.  Saving that however, the focus of test-driven development &#8211; namely unit tests, should be on the business logic that is proprietary to your applicatiom, be it the front-end or the middle tier.</p>
<p>Now, suffice to say that to a good number of developers and architects this isn&#8217;t news, but if you really want to <em>isolate</em> the code which you wrote that is specific to your business rules and requirements &#8211; <strong>mocking frameworks</strong> are the way to go.  Particularly in an Agile project where we can readily identify certain injected dependencies (like an EntityManager, for example) as a <em>collaborator </em>of the class under test, your unit test is really interested in asking the question <em>based on this interaction with this external component, how should I expect my logic to react?</em></p>
<p>In these scenarios of course, I mock or stub the <em>EntityManager</em>.  In the past, a fool like me would have tried to load a container within my unit test environment.  This is actually an integration test, in addition to the fact that it is costly and doesn&#8217;t add the value a truly isolated unit test which focuses on the code <em>you wrote</em> does.</p>
<p>In .Net, <a title="RhinoMocks" href="http://ayende.com/projects/rhino-mocks.aspx" target="_blank">RhinoMocks</a> is scalding hot with it&#8217;s supprt for mocking through lambda&#8217;s.  In JEE, I&#8217;ve fallen in love with <a title="Mockito" href="http://mockito.org/" target="_self">Mockito</a>.</p>
<p>So, stop worrying about how you can get JBoss running so that your CI environment can execute inside of it.  Instead, use mocks to give your code the resources it needs to vet out the conditions in your own code that you want to test.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannorris.com/2009/04/08/mocks-the-only-thing-separating-complex-tdd-from-value-added-tdd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
