<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>I am searching for a new TDD example</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx</link><description>I am looking for a new example to demonstrate Test Driven Development. In the TDD book that Alexei and I wrote we demonstrated TDD using a Stack. For a copy of the chapter see http://workspaces.gotdotnet.com/tdd . We felt that this was a good example</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title> James Newkirk s Blog I am searching for a new TDD example | home lighting</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#9779804</link><pubDate>Fri, 19 Jun 2009 08:44:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9779804</guid><dc:creator> James Newkirk s Blog I am searching for a new TDD example | home lighting</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://homelightingconcept.info/story.php?id=1642"&gt;http://homelightingconcept.info/story.php?id=1642&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9779804" width="1" height="1"&gt;</description></item><item><title> James Newkirk s Blog I am searching for a new TDD example | fix my credit</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#9764704</link><pubDate>Wed, 17 Jun 2009 05:15:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9764704</guid><dc:creator> James Newkirk s Blog I am searching for a new TDD example | fix my credit</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://fixmycrediteasily.info/story.php?id=5651"&gt;http://fixmycrediteasily.info/story.php?id=5651&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9764704" width="1" height="1"&gt;</description></item><item><title> James Newkirk s Blog I am searching for a new TDD example | Toe Nail Fungus</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#9713090</link><pubDate>Tue, 09 Jun 2009 09:01:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9713090</guid><dc:creator> James Newkirk s Blog I am searching for a new TDD example | Toe Nail Fungus</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://toenailfungusite.info/story.php?id=3697"&gt;http://toenailfungusite.info/story.php?id=3697&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9713090" width="1" height="1"&gt;</description></item><item><title> James Newkirk s Blog I am searching for a new TDD example | Wood TV Stand</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#9687496</link><pubDate>Wed, 03 Jun 2009 01:17:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9687496</guid><dc:creator> James Newkirk s Blog I am searching for a new TDD example | Wood TV Stand</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://woodtvstand.info/story.php?id=86018"&gt;http://woodtvstand.info/story.php?id=86018&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9687496" width="1" height="1"&gt;</description></item><item><title> James Newkirk s Blog I am searching for a new TDD example | Outdoor Ceiling Fans</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#9670443</link><pubDate>Sun, 31 May 2009 19:43:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9670443</guid><dc:creator> James Newkirk s Blog I am searching for a new TDD example | Outdoor Ceiling Fans</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://outdoorceilingfansite.info/story.php?id=2463"&gt;http://outdoorceilingfansite.info/story.php?id=2463&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9670443" width="1" height="1"&gt;</description></item><item><title> James Newkirk s Blog I am searching for a new TDD example | Outdoor Ceiling Fans</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#9668428</link><pubDate>Sun, 31 May 2009 13:38:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9668428</guid><dc:creator> James Newkirk s Blog I am searching for a new TDD example | Outdoor Ceiling Fans</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://outdoorceilingfansite.info/story.php?id=20099"&gt;http://outdoorceilingfansite.info/story.php?id=20099&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9668428" width="1" height="1"&gt;</description></item><item><title> James Newkirk s Blog I am searching for a new TDD example | Paid Surveys</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#9659606</link><pubDate>Sat, 30 May 2009 01:30:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9659606</guid><dc:creator> James Newkirk s Blog I am searching for a new TDD example | Paid Surveys</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://paidsurveyshub.info/story.php?title=james-newkirk-s-blog-i-am-searching-for-a-new-tdd-example"&gt;http://paidsurveyshub.info/story.php?title=james-newkirk-s-blog-i-am-searching-for-a-new-tdd-example&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9659606" width="1" height="1"&gt;</description></item><item><title>Copyright Revewals &amp;raquo; James Newkirk&amp;#8217;s Blog : I am searching for a new TDD example</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#8343918</link><pubDate>Sun, 30 Mar 2008 04:49:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8343918</guid><dc:creator>Copyright Revewals » James Newkirk’s Blog : I am searching for a new TDD example</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://copyrightrenewalsblog.info/james-newkirks-blog-i-am-searching-for-a-new-tdd-example/"&gt;http://copyrightrenewalsblog.info/james-newkirks-blog-i-am-searching-for-a-new-tdd-example/&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8343918" width="1" height="1"&gt;</description></item><item><title>Movies &amp;raquo; James Newkirk&amp;#8217;s Blog : I am searching for a new TDD example</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#6931549</link><pubDate>Tue, 01 Jan 2008 09:42:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6931549</guid><dc:creator>Movies » James Newkirk’s Blog : I am searching for a new TDD example</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://movies.247blogging.info/?p=1455"&gt;http://movies.247blogging.info/?p=1455&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6931549" width="1" height="1"&gt;</description></item><item><title>re: I am searching for a new TDD example</title><link>http://blogs.msdn.com/b/jamesnewkirk/archive/2004/08/11/212872.aspx#221852</link><pubDate>Sat, 28 Aug 2004 00:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:221852</guid><dc:creator>Scott Bellware</dc:creator><description>I just did an app as a part of a TDD and OO mentoring and consulting gig that parsed fixed length text files.  It turned out to be a great TDD experience where I was able to demonstrate micro-incremental development and evolving code.  The goal was to create simple business objects that would encapsulate a row of fixed length text data (and ultimately to write a reader that would pull data from a file and feed it into the parsing objects).&lt;br&gt;&lt;br&gt;The example worked really well because we could start with a simple test fixture that has a string member (called “rowData” or what-have-you), and write test methods that asserted that certain values were located at certain indexes on the row.  The simplest test fixture looked like the following:&lt;br&gt;&lt;br&gt;[TestFixture]&lt;br&gt;public class RowFixture&lt;br&gt;{&lt;br&gt;	string rowData = &amp;quot;1JimNewkirk&amp;quot;;&lt;br&gt;&lt;br&gt;	[Test]&lt;br&gt;	public void Id()&lt;br&gt;	{&lt;br&gt;		Assert.AreEqual(&amp;quot;1&amp;quot;, this.rowData.Substring(0, 1));&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	[Test]&lt;br&gt;	public void FirstName()&lt;br&gt;	{&lt;br&gt;		Assert.AreEqual(&amp;quot;Jim&amp;quot;, this.rowData.Substring(1, 3));&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	[Test]&lt;br&gt;	public void LastName()&lt;br&gt;	{&lt;br&gt;		Assert.AreEqual(&amp;quot;Newkirk&amp;quot;, this.rowData.Substring(4, 7));&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;This was before we even had a target class to test.  Next we identified some repetition that we wanted to encapsulate.  Rather than have to invoke String.Substring(), we decided to encapsulate these calls, which led to encapsulating the row data:&lt;br&gt;&lt;br&gt;public class Row&lt;br&gt;{&lt;br&gt;	private string data;&lt;br&gt;&lt;br&gt;	public string Id&lt;br&gt;	{&lt;br&gt;		get{return this.data.Substring(0, 1);}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public string FirstName&lt;br&gt;	{&lt;br&gt;		get{return this.data.Substring(1, 3);}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public string LastName&lt;br&gt;	{&lt;br&gt;		get{return this.data.Substring(4, 7);}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public Row(string data)&lt;br&gt;	{&lt;br&gt;		this.data = data;&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;With the fixture:&lt;br&gt;&lt;br&gt;public class RowFixture&lt;br&gt;{&lt;br&gt;	string rowData = &amp;quot;1JimNewkirk&amp;quot;;&lt;br&gt;	Row row;&lt;br&gt;&lt;br&gt;	[SetUp]&lt;br&gt;	public void CreateRow()&lt;br&gt;	{&lt;br&gt;		this.row = new Row(this.rowData);&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	[Test]&lt;br&gt;	public void Id()&lt;br&gt;	{&lt;br&gt;		Assert.AreEqual(&amp;quot;1&amp;quot;, this.row.Id);&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	[Test]&lt;br&gt;	public void FirstName()&lt;br&gt;	{&lt;br&gt;		Assert.AreEqual(&amp;quot;Jim&amp;quot;, this.row.FirstName);&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	[Test]&lt;br&gt;	public void LastName()&lt;br&gt;	{&lt;br&gt;		Assert.AreEqual(&amp;quot;Newkirk&amp;quot;, this.row.LastName);&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;We then tackled the duplication of calls to Substring() by  creating a ParsedField class:&lt;br&gt;&lt;br&gt;public class ParsedField&lt;br&gt;{&lt;br&gt;	private readonly int startIndex;&lt;br&gt;	private readonly int length;&lt;br&gt;	private readonly Row row;&lt;br&gt;&lt;br&gt;	internal int StartIndex&lt;br&gt;	{&lt;br&gt;		get{return this.startIndex;}	&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	internal int Length&lt;br&gt;	{&lt;br&gt;		get{return this.length;}	&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public string Value&lt;br&gt;	{&lt;br&gt;		get{return this.row.Data.Substring(this.startIndex, this.length);}&lt;br&gt;	}&lt;br&gt;	&lt;br&gt;	public ParsedField(int startIndex, int length, Row row)&lt;br&gt;	{&lt;br&gt;		this.startIndex = startIndex;&lt;br&gt;		this.length = length;&lt;br&gt;		this.row = row;&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;And the fixture:&lt;br&gt;&lt;br&gt;[TestFixture]&lt;br&gt;public class ParsedFieldFixture&lt;br&gt;{&lt;br&gt;	[Test]&lt;br&gt;	public void Value()&lt;br&gt;	{&lt;br&gt;		Row row = new Row(&amp;quot;1&amp;quot;);&lt;br&gt;		ParsedField parsedField = new ParsedField(0, 1, row);&lt;br&gt;		Assert.AreEqual(&amp;quot;1&amp;quot;, parsedField.Value);&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;Which caused us to create the Data property on Row:&lt;br&gt;&lt;br&gt;public string Data&lt;br&gt;{&lt;br&gt;	get{return this.data;}&lt;br&gt;}&lt;br&gt;&lt;br&gt;We then changed the Row class to use the ParsedField class:&lt;br&gt;&lt;br&gt;public class Row&lt;br&gt;{&lt;br&gt;	private string data;&lt;br&gt;&lt;br&gt;	private ParsedField idField;&lt;br&gt;	private ParsedField firstNameField;&lt;br&gt;	private ParsedField lastNameField;&lt;br&gt;&lt;br&gt;	public string Data&lt;br&gt;	{&lt;br&gt;		get{return this.data;}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public string Id&lt;br&gt;	{&lt;br&gt;		get{return this.idField.Value;}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public string FirstName&lt;br&gt;	{&lt;br&gt;		get{return this.firstNameField.Value;}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public string LastName&lt;br&gt;	{&lt;br&gt;		get{return this.lastNameField.Value;}&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public Row(string data)&lt;br&gt;	{&lt;br&gt;		this.data = data;&lt;br&gt;&lt;br&gt;		this.idField = new ParsedField(0, 1, this);&lt;br&gt;		this.firstNameField = new ParsedField(1, 3, this);&lt;br&gt;		this.lastNameField = new ParsedField(4, 7, this);&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;We ultimately refactored the tests to reuse the Row instance through inheritance, made the Row abstract and created a TestRow with the specifics, etc.  It was a good way for me to teach TDD and OO in a context that the developers could identify with, without getting into data connections, etc.&lt;br&gt;&lt;br&gt;The framework later evolves to use strongly-typed readers, type discriminators, and all kinds of simple yet complicated things for a non-OO person to whet their OO appetite with.&lt;br&gt;&lt;br&gt;I’ll be using this example in some upcoming presentations on TDD in my area of the world this fall.&lt;br&gt;&lt;br&gt;Cheers!&lt;br&gt;&lt;br&gt;(And I too love the book… one of the best books on programming – period – since Refactoring.  Much thanks from me and my team!)&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=221852" width="1" height="1"&gt;</description></item></channel></rss>