<?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>Jorge Manrubia &#187; Agile</title>
	<atom:link href="http://jorgemanrubia.net/category/agile/feed/" rel="self" type="application/rss+xml" />
	<link>http://jorgemanrubia.net</link>
	<description>Personal Page</description>
	<lastBuildDate>Sat, 26 Jun 2010 07:36:42 +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>About agile estimating in hours</title>
		<link>http://jorgemanrubia.net/2009/09/08/about-agile-estimating-in-hours/</link>
		<comments>http://jorgemanrubia.net/2009/09/08/about-agile-estimating-in-hours/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 22:12:03 +0000</pubDate>
		<dc:creator>Jorge Manrubia</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://jorgemanrubia.net/2009/09/08/about-estimating-in-hours/</guid>
		<description><![CDATA[In this post I would like to talk about the practice of estimating tasks in hours in the iteration planning. After more than one year applying agile estimating techniques at work, I have changed my mind about this practice, and I would like to share my conclusions. We started the development with the following SCRUM [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I would like to talk about the practice of estimating tasks in hours in the iteration planning. After more than one year applying agile estimating techniques at work, I have changed my mind about this practice, and I would like to share my conclusions.</p>

<p>We started the development with the following SCRUM configuration:</p>

<ul>
<li>Iterations of 4 weeks.</li>
<li>The Release Backlog is composed of user stories which are estimated in story points.</li>
<li>The Iteration Backlogs are composed of the selected user stories for the iteration, which are decomposed into tasks, that are estimated in hours.</li>
</ul>

<p>This approach is supported by several books, including the <a href="http://www.amazon.com/Agile-Software-Development-Scrum/dp/0130676349/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1252429908&amp;sr=8-2">original Scrum book</a> and the superb Mike Cohn&#8217;s <a href="http://www.amazon.com/Agile-Estimating-Planning-Mike-Cohn/dp/0131479415/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1252429950&amp;sr=8-1"><em>Agile Estimating and Planning</em> book</a>. The original Scrum proposal recommends 4 weeks as the duration of each sprint (iteration). Regarding to the backlog contents, the original proposal talks about features as the main item for the product backlog, and tasks for the iteration backlog. Features would be estimated in days and tasks in hours.</p>

<p>Mike Cohn elaborated on this proposing to use user stories as the main product backlog artifact, and tasks for the iteration backlog. He proposes to estimate user stories with ideal days or story points, and tasks in hours. It is worth to notice that the user stories technique was popularized by Kent Beck in his seminar <a href="http://www.amazon.com/Extreme-Programming-Explained-Embrace-Change/dp/0201616416"><em>Extreme Programming Explained</em> book</a>. In the first edition of the book, Kent Beck proposed to estimate the size of stories with points (1,2 or 3). But in the second edition he advocates for using real time estimates. In the same way, he proposes splitting stories into tasks and says that developers should estimate them, although many XP practitioners prefer not to estimate tasks at all, or even to create stories as small as possible in order to eliminate the need for separate tasks.</p>

<p>After several weeks applying the mentioned approach, I realized that there were some aspects I didn&#8217;t like in our planning strategy. The process of splitting stories into tasks and, specially, the estimation of each task was a high time-consuming activity for the project and added little value. I think that this activity was becoming what Lean people call <em>waste</em>:</p>

<ul>
<li><p>Foreseeing estimations at the task level is, by definition, very inaccurate. It is not worth to think thoroughly about how many hours are you going to spend in implementing some subsystem and its tests. Specially if you do it one, two or three weeks before you do it. You&#8217;ll be wrong, because <a href="http://jeffsutherland.com/2002/05/agile-software-development-wicked.html">software development is a wicked problem</a>.</p></li>
<li><p>If you are going to manage inaccurate estimations at the task level, you have added no value to the story point estimations you already have. These can be converted into real time easily using your team speed so, why bother in the extra-effort?.</p></li>
<li><p>In order to determine the tasks that need to be done for implementing a story, there are two contradictory forces:</p>

<ul>
<li><p>If you don&#8217;t want to get deep in the design (after all, you are in an estimation meeting) you end up with a very similar set of tasks for many stories:  design meeting, implementation, testing, documentation&#8230;</p>

<p>Regarding to this, I found very artificial to estimate the hours you spend writing tests and implementing something. Can you separate both activities in a realistic way?</p></li>
<li><p>If you get deep in the design inside a planning meeting so you can create very specific tasks, then you are mixing two very different activities: design and planning. Each requires a very high amount of energy. I have found far more productive to postpone design discussions for late meetings where people can focus completely in the thing to be designed. When you are in a planning meeting you look at the whole number of stories from a very high point of view.</p></li>
</ul></li>
</ul>

<p>In my opinion, the main advantage of having tasks estimated in hours is that you can see how many hours are burnt daily in the sprint backlog, so it&#8217;s very clear how the team advances each day. However, only with the daily meeting and keeping the stories small you can perceive a good sprint progress information.</p>

<p>While the story-points estimations worked very well for estimating our release planning, I found that splitting and estimation of tasks with hours was very inaccurate and someway artificial.</p>

<p>So we decided to stop splitting stories into tasks (not only stop estimating them in hours, we stopped managing tasks as first-class planning artifacts). We want very small stories so we force ourselves to split them when necessary (while keeping them <a href="http://www.artima.com/intv/tracer.html">tracer bullets</a>). And I don&#8217;t really miss tasks. Certainly, there are many times where it is useful to write down the high-level tasks that are needed for implementing some story, but we are fine capturing them as informal comments with the story.</p>

<p>In this process of improving our development method, we first used <a href="http://agilesoftwaredevelopment.com/scrum/simple-product-backlog">Excel templates  for managing our backlogs</a>. After that, we used <a href="http://www.agile42.com/cms/pages/agilo/">Agilo</a>: a very nice tool based on <a href="http://trac.edgewall.org/">trac</a> that can be easily deployed as a VMWare Appliance. It supported perfectly the estimation in story points and hours for the product backlog and the sprint backlog, respectively. When we changed our planning approach we started using <a href="http://www.pivotaltracker.com/">Pivotal Tracker</a>. Pivotal Tracker is an amazing tool. Funny enough, I proposed to their creators <a href="http://getsatisfaction.com/pivotal/topics/possibility_of_specifying_tasks_for_each_story_and_estimating_them_in_hours">to have the possibility of dividing stories into tasks and estimating them in hours</a>. Many people liked this feature, which is currently <a href="http://getsatisfaction.com/pivotal/products/pivotal_tracker?page=1&amp;sort=most_me_toos&amp;style=topics">the number 8th in Pivotal Tracker Most popular topics</a>. The first topic was <a href="http://getsatisfaction.com/pivotal/topics/it_would_be_great_to_add_tasks_to_a_story">add tasks to a story</a> and they have already implemented it in a very nice and simple way (with no estimations of course).</p>

<p>In sum, in our current process:</p>

<ul>
<li>We have iterations of 2 weeks (we preferred a shorter delivery cycle)</li>
<li>We manage user stories as the only planning artifact in our backlogs (release, product and sprint).</li>
<li>We use tasks for clarification of some stories, not as a general planning item.</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://jorgemanrubia.net/2009/09/08/about-agile-estimating-in-hours/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The role of models in Agile and Model Driven Development approaches</title>
		<link>http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/</link>
		<comments>http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 23:31:59 +0000</pubDate>
		<dc:creator>Jorge Manrubia</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Model Driven Engineering]]></category>

		<guid isPermaLink="false">http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/</guid>
		<description><![CDATA[When I was at the university, I remember being very interested in the suggestion that building software was like building bridges, and that software should have blueprints as sophisticated as those needed to build a bridge. I remember to has been told that you will never find a book on &#8220;How to build bridges in [...]]]></description>
			<content:encoded><![CDATA[<p>When I was at the university, I remember being very interested in the suggestion that building software was like building bridges, and that software should have blueprints as sophisticated as those needed to build a bridge. I remember to has been told that you will never find a book on &#8220;How to build bridges in 7 days&#8221; but you will find the equivalent on &#8220;how to learn C++ in 7 days&#8221;.</p>

<p>Today, I&#8217;m not so convinced that this analogy is a good one. I can&#8217;t agree more with <a href="http://pragdave.blogs.pragprog.com/pragdave/2007/10/art-in-programm.html">this quote from Dave Thomas</a> (the <a href="http://www.artima.com/intv/gardenP.html">Pragmatic Programmers proposed a new analogy</a> that I&#8217;m pretty sure not everyone can digest):</p>

<blockquote>
  <p>Software development is neither. Nor is it art. It&#8217;s just software development. People who look for the &#8220;software is like xxx&#8221; analogies are missing the point. Software development is like software development. Let&#8217;s decide what works for us, and have fun while doing it</p>
</blockquote>

<p>If you are interested, <a href="http://martinfowler.com/articles/newMethodology.html#PredictiveVersusAdaptive">Martin Fowler explains the reasons why the building bridges analogy fails</a>. I think, there is a sentence in his article that summarizes the problem very well:</p>

<blockquote>
  <p>Can you get a design that is capable of turning the coding into a predictable construction activity? And if so, is cost of doing this sufficiently small to make this approach worthwhile?</p>
</blockquote>

<p>This question is, obviously, rhetorical. You won&#8217;t. Traditionally, the gap between models and code has been huge. If you ignore this gap, then you may think that you have to make great efforts in creating very rich models, so the low-skilled and no-talented programmer can translate them into working code. And if you can create these models, then nothing stops you from planning the full development process up-front. Since the construction phase is mechanical and predictable, then you only have to calculate how much time you will have to spend in modeling. And since modeling is about drawing (if we use this development approach we are using UML for modeling everything for sure), this estimation should be easy too. After all, drawings, like Word documents or Power Point slides, always compile and work. Of course, this scenery would mean that <a href="http://www.cioupdate.com/insights/article.php/3801091/Why-Software-Development-Projects-Fail-Part-I.htm">software projects are delivered on time</a>, that the waterfall approach works, and that no matter wether the developers are talented or not.</p>

<p>In my opinion, the fact that models can&#8217;t be converted into code easily is addressed by the two development approaches I am more interested in:</p>

<ul>
<li><p>Agile development</p></li>
<li><p>Model Driven Engineering (<acronym title="Model Driven Engineering">MDE</acronym>)</p></li>
</ul>

<p>Although both approaches are perfectly compatible, they propose different ways when it comes to use models. Both approaches see models as a communication tool, as a resource that let us, as humans, reason and elaborate solutions that solve complex problems. While agile practitioners warns you against using models for anything more than this, <acronym title="Model Driven Engineering">MDE</acronym> practitioners propose to take the next step and convert models into first-class development artifacts.</p>

<p>The two approaches give different answers to the question of being able to create designs that can turn the coding into a predictable activity:</p>

<ul>
<li><p>Agile developers&#8217; answer is &#8220;no&#8221;. In fact, they propose to use many good development practices and exhaustive testing as a shield against problems when coding. Coding is not an ugly phase, neither is cleanly separated from design. There are not designers and programmers, there are developers. They will use models as a way to collaboratively obtain the best designs that solve the problem, not as a way of documenting it. And since they assume they can&#8217;t predict how the full process is going to be in earlier stages with detail, they are going to estimate and develop the project iteratively, using an empirical estimating approach.</p></li>
<li><p>The <acronym title="Model Driven Engineering">MDE</acronym> answer is a little bit more complex to say, since the paradigm is in its earlier stages. But if we manage to have <acronym title="Model Driven Engineering">MDE</acronym> solutions where we can define the best DSLs to describe a problem, and to specify how this input is translated into a working application, then, if these DSLs are defined in a way that are reusable in different instances of the same problem, we would be very close to being able to answer &#8220;yes&#8221; to that question.</p></li>
</ul>

<p>By the way, a confluence of both approaches can be seen in the BDD (Behavioral Driven Development) frameworks: such as <a href="http://rspec.info/">RSpec</a>, <a href="http://www.concordion.org/">Concordion</a> or <a href="http://cukes.info/">Cucumber</a>, but I think that topic deserves a post on its own.</p>]]></content:encoded>
			<wfw:commentRss>http://jorgemanrubia.net/2009/04/05/the-role-of-models-in-agile-and-mde-development-approaches/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A nice iPhone tool for agile development</title>
		<link>http://jorgemanrubia.net/2009/02/16/a-nice-iphone-tool-for-agile-development/</link>
		<comments>http://jorgemanrubia.net/2009/02/16/a-nice-iphone-tool-for-agile-development/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 23:02:36 +0000</pubDate>
		<dc:creator>Jorge Manrubia</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://jorgemanrubia.net/2009/02/16/a-nice-iphone-tool-for-agile-development/</guid>
		<description><![CDATA[From time to time I like to check for new applications for my iPhone. It&#8217;s pretty amazing how quickly the base of applications is growing, so I usually discover nice surprises. So today I decided to look for application that was SCRUM-specific. Sincerely I didn&#8217;t expect to find anything, nor I had any concrete application [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time I like to check for new applications for my iPhone. It&#8217;s pretty amazing how quickly the base of applications is growing, so I usually discover nice surprises.</p>

<p>So today I decided to look for application that was <a href="http://en.wikipedia.org/wiki/Scrum_(development)">SCRUM</a>-specific. Sincerely I didn&#8217;t expect to find anything, nor I had any concrete application in mind. The app store search dialog suggested  <a href="http://www.versiontracker.com/dyn/moreinfo/iphone/10904646">ScrumTools</a>. It&#8217;s a very very simple, but still useful, iPhone app. In its current version it offers two things:</p>

<ul>
<li>A timer for controlling the <a href="http://en.wikipedia.org/wiki/Scrum_(development)#Meetings">daily meeting</a> length.</li>
<li>An electronic deck for playing the <a href="http://en.wikipedia.org/wiki/Planning_poker">planning poker</a> activity.</li>
</ul>

<p>Although books usually recommend it, I had never used a timer to control the daily meeting length. If you don&#8217;t take care, these meetings can be easily longer than the 15 minutes recommendation. Since members of the team expose their problems, discussions about how to solve things tend to appear quite often. The solution is as simple as delaying further discussions for specific meetings. The iPhone ScrumTools alerts at 10, 5 and 1 minutes remaining (the normal iPhone timer won&#8217;t do this). I thing is a very good way of focusing the meeting in answering the <a href="http://jeffsutherland.com/scrum/2006/06/why-three-questions-in-daily-scrum.html">three questions</a></p>

<p><img src="http://jorgemanrubia.net/blog/wp-content/uploads/2009/02/screenshot-of-the-timer-of-the-scrumtools-for-iphone.jpg" alt="Screenshot of the timer of the ScrumTools for Iphone" /></p>

<p>Regarding to the Planning Poker activity, if you don&#8217;t know what it is about, you should read <a href="http://www.amazon.com/Agile-Estimating-Planning-Robert-Martin/dp/0131479415">Mike Cohn&#8217;s book on Agile Estimating and Planning</a>. It&#8217;s the best book on agile development I have read. Planning Poker is a technique for estimating size in software development. Basically, for each story:</p>

<ol>
<li>The story is presented and the team discuss about it.</li>
<li>The members of the team choose a card that represents their estimation. We use <a href="http://agilefaq.net/2007/11/13/what-is-a-story-point/">story points</a> in the set proposed by Cohn (1,2,3,5,8,13).</li>
<li>Everyone turn their cards over at the same time.</li>
<li>The members with the lowest and highest estimation expose their reasons, and then the estimation process is repeated. </li>
</ol>

<p>The book tells that teams will find consensus soon. I was a bit skeptical about this after reading the book, but practice has taught me that a consensus is usually reached quickly.</p>

<p><img src="http://jorgemanrubia.net/blog/wp-content/uploads/2009/02/screenshot-of-the-planning-poker-deck-of-the-scrumtools-for-iphone.jpg" alt="Screenshot of the planning poker deck of the ScrumTools for iPhone" /></p>]]></content:encoded>
			<wfw:commentRss>http://jorgemanrubia.net/2009/02/16/a-nice-iphone-tool-for-agile-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating JUnit Test Cases Dynamically</title>
		<link>http://jorgemanrubia.net/2008/09/18/generating-junit-test-cases-dynamically/</link>
		<comments>http://jorgemanrubia.net/2008/09/18/generating-junit-test-cases-dynamically/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 00:53:30 +0000</pubDate>
		<dc:creator>Jorge Manrubia</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://jorgemanrubia.net/blog/?p=48</guid>
		<description><![CDATA[In this post I&#8217;m going to talk about generating JUnit Test Cases Dynamically. In order to define tests, most JUnit&#8217;s users place their testing code inside test methods that Start with test Don&#8217;t have arguments Given a TestCase object, JUnit TestSuites can dynamically extract test methods that follow these conventions and run them on the [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;m going to talk about generating <a href="http://www.junit.org">JUnit</a> Test Cases Dynamically. In order to define tests, most JUnit&#8217;s users place their testing code inside <q>test methods</q> that</p>

<ul>
<li>Start with <code>test</code></li>
<li>Don&#8217;t have arguments</li>
</ul>

<p>Given a <code>TestCase</code> object, JUnit <code>TestSuites</code> can dynamically extract test methods that follow these conventions and run them on the fly. However, this behavior isn&#8217;t enough in some cases. The problem of this approach is that, from the developer&#8217;s point of view, tests must be written statically.</p>

<p>Imagine you have a directory with many text files. For each file, you want to do the same kind of testing. Since the test result depends on each file, what you really want is to generate dynamically test cases. Of course you can have a single test method, and do all the testing there. The main problem of this approach is that Test Runners won&#8217;t be able to collect results properly: a single fail with one file would result as a failure. You won&#8217;t notice which tests are valid and which aren&#8217;t.</p>

<p>Generating tests cases dynamically is very simple. <a href="http://www.riehle.org/2008/04/03/junit-38-documented-using-collaborations/">JUnit&#8217;s design</a> itself is simple. This is one of the main reasons of why this framework is so successful. <a href="http://en.wikipedia.org/wiki/Junit">JUnit was created by Kent Beck and Erich Gamma</a>. It represents an excellent oportunity to see <acronym title="Gang of Four">GOF</acronym> design patterns in action (in the same way that <a href="http://www.jhotdraw.org/">JHotDraw</a>, another framework created by Erich Gamma as a design patterns exercise). In JUnit, a Test Case is, surprisingly, a Test Case. A Test Suite is a <a href="http://en.wikipedia.org/wiki/Composite_pattern">composite</a> of Test Case. You can create a Test Suite as a normal object and, programmatically, populate it with as many instances of a test case as you want.</p>

<p>Let&#8217;s see a very simple example. Imagine you have the following structure of folders:</p>

<p><img src="/blog/wp-content/uploads/2009/02/2008-09-18-junit-sample-folder-structure.png" alt="Folder Structure for the sample" /></p>

<p>For each folder, you want to create a Test Suite. For each file, you want to test that its extension must be <code>.txt</code>. In this way, you are going to create a parallel structure using test suites and test cases.</p>

<p>Below, the test suite is shown. It receives a directory in the constructor. It goes through all the contained files and subdirectories. For each subdirectory, a new <code>TestSuite</code> is created and added to the composite (recursively). For each file, a new <code>TestCase</code> is created and added in the same way. The actual testing is going to be done in these test case instances.</p>

<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TextFileTestSuite <span style="color: #000000; font-weight: bold;">extends</span> TestSuite <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> TextFileTestSuite<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> directory<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>directory.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file <span style="color: #339933;">:</span> directory.<span style="color: #006633;">listFiles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">isDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; addTest<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TextFileTestSuite<span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; addTest<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TextFileTestCase<span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>

<p>The test case&#8217;s implementation is very straighforward. It receives the concrete file to test in the constructor. It also overrides the <code>runTest()</code> method, where the real testing code is placed.</p>

<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TextFileTestCase <span style="color: #000000; font-weight: bold;">extends</span> TestCase <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file<span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> TextFileTestCase<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">file</span> <span style="color: #339933;">=</span> file<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; setName<span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> runTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; assertTrue<span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">endsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span></div></div>

<p>And that&#8217;s all. You can now check the results on a Test Runner:</p>

<div class="codecolorer-container java blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AllTests <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> TEST_FOLDER <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;testdata&quot;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Test suite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; TestSuite suite <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestSuite<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;Test for net.jorgemanrubia.junitdinamically.sample&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//$JUnit-BEGIN$</span><br />
&nbsp; &nbsp; suite.<span style="color: #006633;">addTest</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TextFileTestSuite<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>TEST_FOLDER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//$JUnit-END$</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> suite<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span></div></div>

<p>With the exposed structure of folders, you will obtain something like this:</p>

<p><img src="/blog/wp-content/uploads/2009/02/2008-09-18-junit-sample-test-result.png" alt="Test Results using Eclipse's JUnit Test Runner" /></p>]]></content:encoded>
			<wfw:commentRss>http://jorgemanrubia.net/2008/09/18/generating-junit-test-cases-dynamically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
