<?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>The Code Dump &#187; testing</title>
	<atom:link href="http://www.codelord.net/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codelord.net</link>
	<description>A place a coder rants at...</description>
	<lastBuildDate>Fri, 27 Aug 2010 17:14:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Case Study: Refactoring Interfaces with TDDed Tests</title>
		<link>http://www.codelord.net/2010/06/02/case-study-refactoring-interfaces-with-tdded-tests/</link>
		<comments>http://www.codelord.net/2010/06/02/case-study-refactoring-interfaces-with-tdded-tests/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 19:48:20 +0000</pubDate>
		<dc:creator>abyx</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[software craftsmanship]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=190</guid>
		<description><![CDATA[I&#8217;ve been practicing TDD for a couple of years now, and keep learning all the time. In the past year I&#8217;ve been mainly working on a single project, the longest I&#8217;ve worked on a project with TDD. Putting aside how fun it is (TDD saved me quite a few times for me to be sure [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been practicing TDD for a couple of years now, and keep learning all the time.</p>
<p>In the past year I&#8217;ve been mainly working on a single project, the longest I&#8217;ve worked on a project with TDD. Putting aside how fun it is (TDD saved me quite a few times for me to be sure it&#8217;s worthwhile), working on a project for so long I finally got to see some of the main problems people have against TDD.</p>
<p>With the hundreds of test you have, refactoring on the class-interface level (that is, the interfaces of classes, and not inside classes) can be problematic, with you having to update all the tests.</p>
<p>I&#8217;m still learning how to handle this efficiently, and would like to share an experience I had today. This is an example of a problem regarding 2 collaborators and an interface change. Such refactorings in a TDD environment weren&#8217;t mentioned in the excellent &#8220;<a href="http://www.codelord.net/2010/01/12/every-coder-should-read-tdd-by-example/">TDD by Example</a>&#8221; book and similar works, so I&#8217;m pretty much guessing here.</p>
<p>The example:<br />
<script src="http://gist.github.com/422831.js?file=before+refactoring"></script></p>
<p>The change we&#8217;re interested in is making &#8220;eject&#8221; simply open the lid, without rewinding, and making the rewind operation public. This is in order to allow LazyPerson to take the tape out, without having to wait.  Gary Bernhardt <a href="http://blog.extracheese.org/2009/10/my-personal-failures-in-test-isolation.html">wrote</a> about this kind of changes a bit. I agree, the fact I need to make such a change is against the <a href="http://en.wikipedia.org/wiki/Open/closed_principle">OCP</a>. What can I say, I&#8217;m not perfect and made a design mistake. Saying &#8220;that&#8217;s not OCP&#8221; doesn&#8217;t help me &#8211; <strong>I&#8217;ve got this code and tests, and I need to change them</strong>.</p>
<p>I used to succumb to the temptation and make all the changes in one sweep. That means changing all the tests and the classes, then running the tests and hope they still pass. This, of course, is a crappy way of doing this. Had I been able to actually perform such tasks, I&#8217;d write less tests.  The secret is <strong>baby steps</strong>. The pressure Kent Beck puts on baby steps and gradually working towards change made me consider this and force myself to find a safe way of doing this.</p>
<p>I decided to start with the VCR and its test (the AutomaticPresenter doesn&#8217;t use the VCR itself but an interface, and the tests use test doubles. This means changing one part won&#8217;t break the other&#8217;s unit tests).  The path to enlightenment lies in finding the baby step that allows starting the refactoring without breaking the rest of the tests. I decided to add a test for the should-now-be-public &#8220;rewind&#8221; operation, while not breaking the existing tests.</p>
<p>The solution is adding a default value for telling the &#8220;eject&#8221; function whether it should rewind or not. This means existing users (be them tests or not) will still get the previous behavior, and new tests can start work with the new interface (in Java I&#8217;d probably do this with method overloading): <script src="http://gist.github.com/422856.js?file=mid+refactoring"></script></p>
<p>This got me to <span style="color: #00ff00;">green</span> pretty fast. Now I can slowly remove every rewind-related assertion from the old tests and also add the &#8220;should_rewind=False&#8221; flag to them, all with quick-green cycles. And we&#8217;re done with the first half.</p>
<p>The next move is to change the AutomaticPresenter to call &#8220;rewind&#8221; before &#8220;eject&#8221;, which is now really easy to do in the tests. Once we hit green, we remove the &#8220;should_rewind&#8221; flag and be done with the refactoring. Baby steps save the day:<br />
<script src="http://gist.github.com/422862.js?file=post+refatoring"></script></p>
<p>Being able to get the refactoring working so easily makes me happy, but I&#8217;m still not sure this is the smartest way, and there are harder refactorings to master ahead. Yet, I hope this will help TDD adopters see that it&#8217;s possible to handle refactorings even with many tests, because once the right baby-step is found, each test can take practically seconds to convert.</p>
<p>I&#8217;d really love getting feedback on this cycle.</p>
<p>You should subscribe to my <a href="http://feeds.feedburner.com/TheCodeDump">RSS</a> feed or follow me on <a href="http://www.twitter.com/avivby">twitter</a>!
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2010%2F06%2F02%2Fcase-study-refactoring-interfaces-with-tdded-tests%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2010%2F06%2F02%2Fcase-study-refactoring-interfaces-with-tdded-tests%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2010/06/02/case-study-refactoring-interfaces-with-tdded-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python (nose) Test Coverage on Buildbot</title>
		<link>http://www.codelord.net/2010/05/09/python-nose-test-coverage-on-buildbot/</link>
		<comments>http://www.codelord.net/2010/05/09/python-nose-test-coverage-on-buildbot/#comments</comments>
		<pubDate>Sun, 09 May 2010 17:03:07 +0000</pubDate>
		<dc:creator>abyx</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[buildbot]]></category>
		<category><![CDATA[nose]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=155</guid>
		<description><![CDATA[Once we got our builds happily running on Buildbot, there&#8217;s really no reason not to add coverage since it&#8217;s so easy (especially if you get bragging rights over your non-TDDers teammates). All you have to do is this (code is based on this blog post, with adaptations to work on slaves that don&#8217;t share directories [...]]]></description>
			<content:encoded><![CDATA[<p>Once we got our builds happily running on Buildbot, there&#8217;s really no reason not to add coverage since it&#8217;s so easy (especially if you get bragging rights over your non-TDDers teammates).</p>
<p>All you have to do is this (code is based on this <a href="http://copypasteprogrammer.blogspot.com/2010/03/buildbot-and-nose-test-coverage.html">blog post</a>, with adaptations to work on slaves that don&#8217;t share directories with the master, since the createSummary method runs on the master):</p>
<p><script src="http://gist.github.com/395269.js"></script>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2010%2F05%2F09%2Fpython-nose-test-coverage-on-buildbot%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2010%2F05%2F09%2Fpython-nose-test-coverage-on-buildbot%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2010/05/09/python-nose-test-coverage-on-buildbot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nose doesn&#8217;t discover tests on Solaris</title>
		<link>http://www.codelord.net/2010/03/03/nose-doesnt-discover-tests-on-solaris/</link>
		<comments>http://www.codelord.net/2010/03/03/nose-doesnt-discover-tests-on-solaris/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 14:05:31 +0000</pubDate>
		<dc:creator>abyx</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[techie]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=138</guid>
		<description><![CDATA[Note: this is a technical post, to help poor souls that google this When using nose on Solaris machines, simply running nosetests without specifying the file names will not work if you are the root user. To fix this, you must either not be root, or pass nose the argument --exe. That&#8217;s it. Gory details: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note:</strong> this is a technical post, to help poor souls that google this <img src='http://www.codelord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>When using <em>nose</em> on Solaris machines, simply running <em>nosetests</em> without specifying the file names will not work if you are the root user. To fix this, you must either not be root, or pass <em>nose</em> the argument <code>--exe</code>. That&#8217;s it.</p>
<p>Gory details: by default, <em>nose</em> ignores executable files. Each file it encounters it checks with <em>os.access(test_file, os.X_OK)</em> to see if it&#8217;s executable. Problem is that Solaris&#8217; <em>access</em> function always returns success for root, regardless of actual file permissions. This is discouraged by POSIX, but known behavior.</p>
<p>I hope this saves someone the 3 hours it wasted for me <img src='http://www.codelord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2010%2F03%2F03%2Fnose-doesnt-discover-tests-on-solaris%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2010%2F03%2F03%2Fnose-doesnt-discover-tests-on-solaris%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2010/03/03/nose-doesnt-discover-tests-on-solaris/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
