<?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>Sat, 04 Feb 2012 12:53:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Extend Your Toolbox: Custom Matchers</title>
		<link>http://www.codelord.net/2012/02/04/extend-your-toolbox-custom-matchers/</link>
		<comments>http://www.codelord.net/2012/02/04/extend-your-toolbox-custom-matchers/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 12:53:41 +0000</pubDate>
		<dc:creator>Aviv Ben-Yosef</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[DRY]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software craftsmanship]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=726</guid>
		<description><![CDATA[I&#8217;d like to point out a really nice testing practice that I&#8217;ve been loving more and more lately. Just about every mature testing framework out there supports the concept of custom matchers, which provide us with the ability to define our very own assertions seamlessly into the tests. Even though this ability is quite old, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to point out a really nice testing practice that I&#8217;ve been loving more and more lately.</p>
<p>Just about every mature testing framework out there supports the concept of custom matchers, which provide us with the ability to define our very own assertions seamlessly into the tests. Even though this ability is quite old, we don&#8217;t see it used too often and I think that&#8217;s a shame. I&#8217;ve seen this practice heavily used in the mind expanding <a href="http://www.amazon.com/gp/product/0321503627?ie=UTF8&amp;tag=thcodu02-20&amp;linkCode=shr&amp;camp=213733&amp;creative=393185&amp;creativeASIN=0321503627">GOOS</a> book and just now am starting to realize its awesomeness.<br />
<div class="wp-caption alignright" style="width: 250px"><a href="http://www.flickr.com/photos/dipster1/1403240351/"><img title="Your Testing Toolbox" src="http://farm2.staticflickr.com/1155/1403240351_68114a0c53.jpg" alt="toolbox" width="240" height="126" /></a><p class="wp-caption-text">Your Testing Toolbox</p></div><br />
Note: examples in this post are shown in Ruby using <a href="https://github.com/dchelimsky/rspec/wiki/Custom-Matchers">RSpec&#8217;s matchers</a> but the concept is pretty much identical (as can be seen for example in Java&#8217;s <a href="http://code.google.com/p/hamcrest/wiki/Tutorial">Hamcrest Matchers</a>).</p>
<h3>Matchers 101</h3>
<p>Creating your own matcher usually means creating a Matcher class that performs the assertions, supplies human readable error messages and a nice constructor.</p>
<p>Here&#8217;s an example from the <a href="https://github.com/dchelimsky/rspec/wiki/Custom-Matchers">RSpec documentation</a>:</p>
<div id="gist-1737631" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="no">RSpec</span><span class="o">::</span><span class="no">Matchers</span><span class="o">.</span><span class="n">define</span> <span class="ss">:be_a_multiple_of</span> <span class="k">do</span> <span class="o">|</span><span class="n">expected</span><span class="o">|</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="n">match</span> <span class="k">do</span> <span class="o">|</span><span class="n">actual</span><span class="o">|</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">actual</span> <span class="o">%</span> <span class="n">expected</span> <span class="o">==</span> <span class="mi">0</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC5'><span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1737631/2d0980f927c298854d8ace00013c2f1a5f28dedd/rspec_matcher.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1737631#file_rspec_matcher.rb" style="float:right;margin-right:10px;color:#666">rspec_matcher.rb</a>
            <a href="https://gist.github.com/1737631">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h3>Matchers increase readability and intent</h3>
<p>As you should know, one of the <a href="http://c2.com/cgi/wiki?XpSimplicityRules">most important rules for design</a> is <em>Reveals Intent</em>. Take a quick look here, which way do you think reveals more intent?</p>
<div id="gist-1737631" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1"># This</span></div><div class='line' id='LC2'><span class="n">response</span><span class="o">[</span><span class="s1">&#39;X-Runtime&#39;</span><span class="o">].</span><span class="n">should</span> <span class="o">=~</span> <span class="sr">/[\d\.]+/</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="c1"># .. or this?</span></div><div class='line' id='LC5'><span class="n">response</span><span class="o">[</span><span class="s1">&#39;X-Runtime&#39;</span><span class="o">].</span><span class="n">should</span> <span class="n">be_a_number</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1737631/215e237f07b383c5792cbb5cca0adcc2b5f4864a/intent.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1737631#file_intent.rb" style="float:right;margin-right:10px;color:#666">intent.rb</a>
            <a href="https://gist.github.com/1737631">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Also, which error message do you prefer? &#8220;expected false to be true&#8221; or something along the lines of &#8220;expected comment to be anonymous&#8221;?</p>
<h3>Matchers create robust tests</h3>
<p>The most important advantage of all is how using matchers easily allows you to steer away from fragile tests which are the bane of a lot of testing efforts.<br />
The mark of good tests is that a change in your code doesn&#8217;t require you to perform changes in multiple tests that don&#8217;t really care for the change.<br />
Take this code for example:</p>
<div id="gist-1737631" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="n">expected_comment</span> <span class="o">=</span> <span class="no">Comment</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">anonymous</span><span class="p">:</span> <span class="kp">true</span><span class="p">,</span> <span class="n">user</span><span class="p">:</span> <span class="s2">&quot;the dude&quot;</span><span class="p">,</span> <span class="n">reply_to</span><span class="p">:</span> <span class="kp">nil</span><span class="p">)</span></div><div class='line' id='LC2'><span class="n">commentor</span><span class="o">.</span><span class="n">should_receive</span><span class="p">(</span><span class="ss">:add</span><span class="p">)</span><span class="o">.</span><span class="n">with</span><span class="p">(</span><span class="n">expected_comment</span><span class="p">)</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1737631/af12f952b61c745a7bce91c5980eae0b382d751a/sucky_non_dry.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1737631#file_sucky_non_dry.rb" style="float:right;margin-right:10px;color:#666">sucky_non_dry.rb</a>
            <a href="https://gist.github.com/1737631">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This might seem like a standard test, but that&#8217;s not really the case. A test should assert for a single piece of knowledge, and this test actually checks several. If the purpose of this test is to check the behavior of anonymous comments, why should it change if we no longer allow replies? Or if we no longer require users for posting comments?</p>
<p>The magic of matchers is exactly here. You create a new matcher to check specifically the aspect your test cares about and *boom*, you&#8217;re decoupled!</p>
<div id="gist-1737631" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="n">commentor</span><span class="o">.</span><span class="n">should_receive</span><span class="p">(</span><span class="ss">:add</span><span class="p">)</span><span class="o">.</span><span class="n">with</span><span class="p">(</span><span class="n">anonymous_comment</span><span class="p">)</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1737631/3f386a4f184528f678b316dc45c94cee32c8cae1/beautiful_and_dry.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1737631#file_beautiful_and_dry.rb" style="float:right;margin-right:10px;color:#666">beautiful_and_dry.rb</a>
            <a href="https://gist.github.com/1737631">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>This simple change makes your tests DRY and cool.</p>
<p>Happy testing!</p>
<p>Your should <a href="http://feeds.feedburner.com/TheCodeDump">subscribe</a> to my feed or <a href="http://twitter.com/avivby">follow</a> me on twitter!
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2012%2F02%2F04%2Fextend-your-toolbox-custom-matchers%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2012%2F02%2F04%2Fextend-your-toolbox-custom-matchers%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2012/02/04/extend-your-toolbox-custom-matchers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looking Back on 18 months of Testing and TDD at a Startup</title>
		<link>http://www.codelord.net/2012/01/06/looking-back-on-18-months-of-testing-and-tdd-at-a-startup/</link>
		<comments>http://www.codelord.net/2012/01/06/looking-back-on-18-months-of-testing-and-tdd-at-a-startup/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 20:34:25 +0000</pubDate>
		<dc:creator>Aviv Ben-Yosef</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[billguard]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=701</guid>
		<description><![CDATA[As we&#8217;re approaching a year and half here at BillGuard, I&#8217;ve started thinking back a bit about our testing habits and how well that&#8217;s turned out. I&#8217;ve seen a lot of posts about testing in startups, some saying startups shouldn&#8217;t bother to test because they&#8217;ll have to change the whole damn thing 5 minutes after [...]]]></description>
			<content:encoded><![CDATA[<p>As we&#8217;re approaching a year and half here at <a href="https://www.billguard.com">BillGuard</a>, I&#8217;ve started thinking back a bit about our testing habits and how well that&#8217;s turned out.</p>
<p>I&#8217;ve seen a lot of posts about testing in startups, some saying startups shouldn&#8217;t bother to test because they&#8217;ll have to change the whole damn thing 5 minutes after they&#8217;re done, others claim testing is the only reason they were able to keep working. Here are some of my thoughts looking back.</p>
<h3>Our Background</h3>
<p>When we started, only two of us had a test-infected background out of the five technical guys, me being big on <a href="http://www.amazon.com/gp/product/0321146530/ref=as_li_ss_tl?ie=UTF8&amp;tag=thcodu02-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0321146530">TDD</a><img style="border: none !important; margin: 0px !important; display: none;" src="http://www.assoc-amazon.com/e/ir?t=thcodu02-20&amp;l=as2&amp;o=1&amp;a=0321146530" alt="" width="1" height="1" border="0" />. Two other developers never wrote tests before. We agreed that tests were important, but that&#8217;s about it. I set up a continuous integration server and with that we were off. With time, the habit of writing tests spread out among the team. Some are TDD passionate, some write tests after the fact, but we generally all believe that tests should be written extensively.</p>
<h3></h3>
<div id="attachment_704" class="wp-caption aligncenter" style="width: 250px"><a href="http://www.codelord.net/wp-content/uploads/2012/01/test_in_prod.png"><img class="size-medium wp-image-704 " title="test_in_prod" src="http://www.codelord.net/wp-content/uploads/2012/01/test_in_prod-240x300.png" alt="" width="240" height="300" /></a><p class="wp-caption-text">None of us, ever</p></div>
<h3>Not everything is worth testing</h3>
<p>We&#8217;ve seen several quite rapid changes to our UI. Having less tests in this area makes sense. We rely on QA for making sure all buttons are displayed etc. To make this clear: we have no selenium-like tests for UI components but have tests for most logic being done by the UI. I think this is generally a good practice, since having to maintain selenium tests would be hard when you throw things around a lot and change flows. Some basic automated sanity tests pretty much does it.</p>
<h3>Everyone learned to love tests</h3>
<p>I love seeing other guys in the team delete a line of code to see which test breaks and understand why it&#8217;s there. Even more I love the frowning face when no tests break. This addiction to tests shows how much value the team&#8217;s getting out of having solid tests, hands down. No need to stress this further I believe.</p>
<h3>Tests save our asses repeatedly</h3>
<p>Having an extensive suite of tests allows us to make rapid changes to our code base, as is needed in most startups, and rely on the solid tests to tell us whether we&#8217;ve screwed something up. All the code that has anything whatsoever to do with sensitive and important information is heavily tested which is a huge bonus and a necessity in our line of business (personal finance protection).</p>
<h3>TDD is just magical with complex algorithms</h3>
<p>We have quite a few complex algorithms that require multiple entities and ideas to perform. I find that the parts we&#8217;re most satisfied with maintainability-wise are the heavily TDD-ed algorithms we&#8217;ve got. Being written with rigorous TDD gives us so many advantages:</p>
<ul>
<li>This critical code usually has a lot less defects.</li>
<li>The code is a lot more readable, well decomposed and allows for easy changing once we find out a need for tweaking the algorithms.</li>
<li>Working in TDD magically forces us to form our problem domain better, making us have a language of our own in talking about the problem. This happens less naturally in other forms of working on algorithms.</li>
</ul>
<h3>Summing our testing experiences</h3>
<p>All in all, I think the whole team would agree that dedicating time to writing thorough tests is proving itself valuable and because of that people are writing more and more tests without any of us ever stopping and saying &#8220;we should write tests&#8221; (well, I swear I didn&#8217;t do it too much). It happens naturally when people get the value out of it. It&#8217;s fun seeing how today BillGuard has become a company that organically values testing so much I don&#8217;t even feel a great need to stress it to new people because they&#8217;ll quickly see there&#8217;s no real other way. We&#8217;re far from being the poster children of <a href="http://www.amazon.com/gp/product/0132350882/ref=as_li_ss_tl?ie=UTF8&amp;tag=thcodu02-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0132350882">Clean Code</a><img style="border: none !important; margin: 0px !important; display: none;" src="http://www.assoc-amazon.com/e/ir?t=thcodu02-20&amp;l=as2&amp;o=1&amp;a=0132350882" alt="" width="1" height="1" border="0" />, but I&#8217;ve got my fingers crossed.</p>
<p>If you&#8217;re interested in accomplishing the same at your work, you might find <a href="http://www.codelord.net/2011/11/28/stop-bitching-write-those-damn-tests/">this recent post</a> of mine of some help.</p>
<p>You should <a href="http://feeds.feedburner.com/TheCodeDump">subscribe</a> to my feed or <a href="http://twitter.com/avivby">follow</a> me on twitter!
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2012%2F01%2F06%2Flooking-back-on-18-months-of-testing-and-tdd-at-a-startup%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2012%2F01%2F06%2Flooking-back-on-18-months-of-testing-and-tdd-at-a-startup%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2012/01/06/looking-back-on-18-months-of-testing-and-tdd-at-a-startup/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Today I Got Burnt by Isolated Tests</title>
		<link>http://www.codelord.net/2011/08/07/today-i-got-burnt-by-isolated-tests/</link>
		<comments>http://www.codelord.net/2011/08/07/today-i-got-burnt-by-isolated-tests/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 21:06:26 +0000</pubDate>
		<dc:creator>Aviv Ben-Yosef</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[goos]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=440</guid>
		<description><![CDATA[Generally, I prefer the GOOS school of TDD which includes isolating my classes as much as possible, putting mocks and stubs everywhere. Even though one of its known disadvantages is that you risk testing your classes in a fake environment that won&#8217;t match the real production code using it, I&#8217;ve rarely come across a place [...]]]></description>
			<content:encoded><![CDATA[<p>Generally, I prefer the <a href="http://www.amazon.com/gp/product/0321503627/ref=as_li_tf_tl?ie=UTF8&amp;tag=thcodu02-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321503627">GOOS</a><img style="display: none; border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=thcodu02-20&amp;l=as2&amp;o=1&amp;a=0321503627" alt="" width="1" height="1" border="0" /> school of TDD which includes isolating my classes as much as possible, putting mocks and stubs everywhere. Even though one of its known disadvantages is that you risk testing your classes in a fake environment that won&#8217;t match the real production code using it, I&#8217;ve rarely come across a place where I got really bitten by it.</p>
<p>Today I set out with my pair to add some functionality to a certain class. That class had about 30-40 lines of code and about 10 test cases, which seemed quite decent. We added our changes TDD style and just couldn&#8217;t get the thing working. After digging into it for a few more minutes we suddenly realized the class shouldn&#8217;t be working at all and checking in the DB showed that indeed the last time that specific feature had any effect was 3 months ago!</p>
<p>Fortunately for us, all the problems that caused this bug are solved problems, we just need to get better at implementing the solutions:</p>
<p>Isolated tests go much better hand in hand with a few <strong><em>integration tests</em></strong> (some might say the right term is acceptance tests) that execute the whole system and make sure the features are working. Had we had those, we would have caught the bug much sooner.</p>
<p>The bug was introduced in a <strong><em>huge commit</em></strong> that changes 35 files and 1500 lines of code. We usually try and go over every commit made, even if it was paired, because we believe in collective code ownership, but it&#8217;s impossible to go over such a huge diff and find these intricacies. Working in small baby steps makes it far less likely to break something and more likely that someone else will spot your mistakes. Huge refactorings give me the creeps.</p>
<p>After the change was committed, it was not <strong><em>followed-through</em></strong>: this specific feature is a feature you usually notice over a few days and we missed out on making sure it kept working. We moved on to other tasks and forgot all about it, thinking it was working all this time. Had we taken the time to make sure we were seeing, it would have been squashed by the next deployment.</p>
<p>Any of these would have helped us spot sooner that the isolated tests were actually testing the code against a scenario that never happens. These tiny changes of our workflow would have made several of our users happier over this timeframe.</p>
<p>Hopefully all is well now and the feature is back at 100%, but only time will tell whether we were able to learn from this mishap.</p>
<p>You should <a href="http://feeds.feedburner.com/TheCodeDump">subscribe</a> to my feed and <a href="http://twitter.com/avivby">follow</a> me on twitter!
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2011%2F08%2F07%2Ftoday-i-got-burnt-by-isolated-tests%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2011%2F08%2F07%2Ftoday-i-got-burnt-by-isolated-tests%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2011/08/07/today-i-got-burnt-by-isolated-tests/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Sometimes Tests Have to Fail</title>
		<link>http://www.codelord.net/2011/04/03/sometimes-tests-have-to-fail/</link>
		<comments>http://www.codelord.net/2011/04/03/sometimes-tests-have-to-fail/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 18:40:18 +0000</pubDate>
		<dc:creator>Aviv Ben-Yosef</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=376</guid>
		<description><![CDATA[A friend asked me about a common problem that pops up in real-world projects and testing: What do you do when you test code with random properties? A simple example might be handing out jobs to a few workers. If your algorithm for doing that is random, you can usually assert that no one of [...]]]></description>
			<content:encoded><![CDATA[<p>A friend asked me about a common problem that pops up in real-world projects and testing: What do you do when you test code with random properties?</p>
<p>A simple example might be handing out jobs to a few workers. If your algorithm for doing that is random, you can usually assert that no one of 3 workers gets all 10 jobs, for example. But, being random, that assert should eventually fail. We&#8217;ll assume that with the frequency the team runs the tests, a failure is expected every few days.</p>
<p>Surely no one wants to see the tests fail a couple times a week (especially if you&#8217;re keeping score for who broke the build). On the other hand, you&#8217;d like to keep the tests. What is a pragmatic coder to do?</p>
<p>If you&#8217;re not that meticulous to your suite rarely failing, you might just leave it as it is, which, I think, sucks.</p>
<p>The mega-tester&#8217;s approach, which I&#8217;ve tried in the past, is usually to stub out the random number generator with values that make sure the failures won&#8217;t happen. This is usually cost-effective only for the simplest of cases, and the more complex ones results in brittle tests that are coupled to the implementation and that might need to be changed frequently.</p>
<p>What I rather is to postpone the problem! Say we change our test&#8217;s parameters to 10 workers and 3000 jobs. The chances of one worker getting all jobs becomes quite minor. This tweak of parameters in the test is usually simple to do and can guarantee quite a safety net.</p>
<p>And still, sometimes bad stuff happen. 64bit hash collisions are somewhere, out there in the world. If you&#8217;re one of those guys that are bugged by that chance, I give you a simple JUnit rule that will retry a specific test in case it fails, making it twice as unlikely to fail. Those 64bit collisions are now more like 128bit! woohoo!</p>
<p>The rule allows you to simply annotate a test to make it retry in case it fails:</p>
<div id="gist-897229" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">RetrierTest</span> <span class="o">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="kd">private</span> <span class="kd">static</span> <span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nd">@Rule</span> <span class="kd">public</span> <span class="n">RetryRule</span> <span class="n">rule</span> <span class="o">=</span> <span class="k">new</span> <span class="n">RetryRule</span><span class="o">();</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="nd">@Test</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="nd">@Retry</span></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="kd">public</span> <span class="kt">void</span> <span class="nf">failsFirst</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">count</span><span class="o">++;</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">assertEquals</span><span class="o">(</span><span class="mi">2</span><span class="o">,</span> <span class="n">count</span><span class="o">);</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="o">}</span></div><div class='line' id='LC12'><span class="o">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/897229/d848f470464d5426fa7482aa5473218f7aa74d8e/RetrierTest.java" style="float:right;">view raw</a>
            <a href="https://gist.github.com/897229#file_retrier_test.java" style="float:right;margin-right:10px;color:#666">RetrierTest.java</a>
            <a href="https://gist.github.com/897229">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>And the implementation is as simple as:</p>
<div id="gist-897229" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nd">@Retention</span><span class="o">(</span><span class="n">RetentionPolicy</span><span class="o">.</span><span class="na">RUNTIME</span><span class="o">)</span></div><div class='line' id='LC2'><span class="kd">public</span> <span class="nd">@interface</span> <span class="n">Retry</span> <span class="o">{}</span></div><div class='line' id='LC3'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/897229/f72b15925563a7fe8d8ef7fc7e8141a5ab3b964a/Retry.java" style="float:right;">view raw</a>
            <a href="https://gist.github.com/897229#file_retry.java" style="float:right;margin-right:10px;color:#666">Retry.java</a>
            <a href="https://gist.github.com/897229">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<div id="gist-897229" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">RetryRule</span> <span class="kd">implements</span> <span class="n">MethodRule</span> <span class="o">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="nd">@Override</span> <span class="kd">public</span> <span class="n">Statement</span> <span class="n">apply</span><span class="o">(</span><span class="kd">final</span> <span class="n">Statement</span> <span class="n">base</span><span class="o">,</span> <span class="kd">final</span> <span class="n">FrameworkMethod</span> <span class="n">method</span><span class="o">,</span> <span class="n">Object</span> <span class="n">target</span><span class="o">)</span> <span class="o">{</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="k">new</span> <span class="nf">Statement</span><span class="o">()</span> <span class="o">{</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nd">@Override</span> <span class="kd">public</span> <span class="kt">void</span> <span class="n">evaluate</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">Throwable</span> <span class="o">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">try</span> <span class="o">{</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">base</span><span class="o">.</span><span class="na">evaluate</span><span class="o">();</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">Throwable</span> <span class="n">t</span><span class="o">)</span> <span class="o">{</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">Retry</span> <span class="n">retry</span> <span class="o">=</span> <span class="n">method</span><span class="o">.</span><span class="na">getAnnotation</span><span class="o">(</span><span class="n">Retry</span><span class="o">.</span><span class="na">class</span><span class="o">);</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="o">(</span><span class="n">retry</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">base</span><span class="o">.</span><span class="na">evaluate</span><span class="o">();</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">}</span> <span class="k">else</span> <span class="o">{</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">throw</span> <span class="n">t</span><span class="o">;</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">}</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">}</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">}</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">};</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="o">}</span></div><div class='line' id='LC18'><span class="o">}</span></div><div class='line' id='LC19'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/897229/9d79a808cd1c26a9b535f7c8dfa8eb2c0f503d55/RetryRule.java" style="float:right;">view raw</a>
            <a href="https://gist.github.com/897229#file_retry_rule.java" style="float:right;margin-right:10px;color:#666">RetryRule.java</a>
            <a href="https://gist.github.com/897229">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>With the tests so unlikely to fail, I&#8217;d start a lottery at work for whoever breaks them.</p>
<p>Happy testing!</p>
<p>You should <a href="http://feeds.feedburner.com/TheCodeDump">subscribe</a> to my feed and <a href="http://twitter.com/avivby">follow</a> me on twitter!
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2011%2F04%2F03%2Fsometimes-tests-have-to-fail%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2011%2F04%2F03%2Fsometimes-tests-have-to-fail%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2011/04/03/sometimes-tests-have-to-fail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Techniques: Managing External Resources</title>
		<link>http://www.codelord.net/2011/04/01/testing-techniques-managing-external-resources/</link>
		<comments>http://www.codelord.net/2011/04/01/testing-techniques-managing-external-resources/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 04:45:32 +0000</pubDate>
		<dc:creator>Aviv Ben-Yosef</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.codelord.net/?p=372</guid>
		<description><![CDATA[A friend approached me with one of the known problems in the testing world &#8211; How do you keep external resources under a test harness? Having heard the question a few times before, I thought I&#8217;d share my thoughts, and mainly put together the common advice that drifts around the web. The Dilemma Nowadays, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>A friend approached me with one of the known problems in the testing world &#8211; How do you keep external resources under a test harness? Having heard the question a few times before, I thought I&#8217;d share my thoughts, and mainly put together the common advice that drifts around the web.</p>
<h3>The Dilemma</h3>
<p>Nowadays, it&#8217;s hard to get more than a 100 lines of code before adding an external resource to our code. It might be a web service to manage something, or some convoluted API to receive data from or just about anything. Usually, writing tests for code that directly talks with these resources using the resources themselves is very problematic, for numerous reasons:</p>
<ul>
<li>It significantly slows the tests, because it requires network access and processing on the service&#8217;s side.</li>
<li>It might cost you money, send emails, tweet stuff and do things you&#8217;d rather not do 300 times a day as you run your tests.</li>
<li>Making your code handle error conditions with the service is hard or impossible, as you can&#8217;t control when those occur.</li>
</ul>
<p>Basically, all of these factors usually amount up to you having crappy tests that you rarely run. That sucks.</p>
<h3>Decouple &amp; Isolate</h3>
<p>The best solution I&#8217;m aware of is simply isolating the thing. We usually strive to wrap whatever service we&#8217;re using with a single-point interface. The decoupling is great since I&#8217;ve yet to encounter a service with an API that matched my thinking of the domain problem. Wrapping it up allows us to keep using our own language and logic throughout the system.</p>
<p>A benefit of that is we now have a simple interface or facade we need to stub/mock out during tests. That&#8217;s usually relatively easy, and allows us to run our tests blazingly fast and test all those hard to reach to corner cases.</p>
<h3>But what if the service changes?</h3>
<p>That&#8217;s the finishing touch. You should still maintain a suite of tests that run against the real service. Those should be the plain tests that make sure you&#8217;re using the API right and that would break if anything you&#8217;re relying on changes. These tests won&#8217;t be part of your regular suite that gets run constantly. Instead have your CI server run them daily/weekly and let you know when something changes.</p>
<p>This puts us basically in a win-win situation, with us being able to run our tests quickly and yet have the assurance that we won&#8217;t miss API changes and the likes.</p>
<p>Happy testing!</p>
<p>You should <a href="http://feeds.feedburner.com/TheCodeDump">subscribe</a> to my feed and <a href="http://twitter.com/avivby">follow</a> me on twitter!
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.codelord.net%2F2011%2F04%2F01%2Ftesting-techniques-managing-external-resources%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2011%2F04%2F01%2Ftesting-techniques-managing-external-resources%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2011/04/01/testing-techniques-managing-external-resources/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Say No to Null Checks</title>
		<link>http://www.codelord.net/2010/11/14/say-no-to-null-checks/</link>
		<comments>http://www.codelord.net/2010/11/14/say-no-to-null-checks/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 20:23:01 +0000</pubDate>
		<dc:creator>Aviv Ben-Yosef</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=267</guid>
		<description><![CDATA[Hey, do you check your methods&#8217; arguments to make sure they&#8217;re not null? Today, I got into a little discussion with a teammate about testing contracts of methods: should we check for null in every public method? I was against it, and he was for it. The simple reasons to do it are, first, that [...]]]></description>
			<content:encoded><![CDATA[<p>Hey, do you check your methods&#8217; arguments to make sure they&#8217;re not null?</p>
<div id="_mcePaste">
<p>Today, I got into a little discussion with a teammate about testing contracts of methods: should we check for null in every public method?</p>
<p>I was against it, and he was for it.</p>
<p>The simple reasons to do it are, first, that it makes your code more defensive. You fail explicitly instead of failing implicitly when the code tries to dereference the null object. Another argument was that given 20 callers of an interface, it&#8217;s easier to test in the interface for the precondition than to test each and every one of the callers. And, of course, that it is better API implementation, and that even if a class isn&#8217;t part of one&#8217;s public API now it might very well become part of it in the future, so why not add the tests now?</p>
<p>I&#8217;ll tackle these all. First, I have to agree that some null checks are required, at the boundaries of your system. I believe a system should have a paranoid barrier, before it everything is as suspect as someone going on a bus with a heavy coat on a hot day &#8211; that&#8217;s just waiting to blow. Once you&#8217;ve passed the barrier you know things are secure and no longer need to be paranoid.</p>
<p>So yes, some null checks are of course required.</p>
<p>But, because we want our API to be user-friendly and error-proof does that mean we need to make every public method in our code paranoid just in case it will become part of the public API at some point? 5 letters: YAGNI! <img src='http://www.codelord.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The interesting part is the testing of the callers. I agree, if we have to write the test 20 times for each caller, it will get tedious. But we don&#8217;t write the same thing twice, do we? As good old J.B Rainsberger <a href="http://blog.thecodewhisperer.com/post/207374113/who-tests-the-contract-tests"><span style="color: #000000;">teaches</span></a>, what we actually need are collaboration tests. Each of the callers collaborate with the interface. And so, we create a collaboration test that makes sure the user is using the interface according to the contract. These are usually abstract tests that require us to create derivatives that implement a factory method for creating the calling class. This way we write the tests only once and make explicit the interface and contract, even in dynamic language.</p>
<p>In general, this is a powerful solution, that solves a basic problem with defensive programming. Say we do test for nullity wherever possible, what do we do then? Our system is likely to crash or throw an exception any way, since what is the interface to do? Obviously something is wrong if we were called in a way that doesn&#8217;t match the contract, so is the hassle worth it? I think testing for nullity everywhere is a thing of the past, especially once you adopt dynamic programming and get used to the fact that most of the times you can&#8217;t even be sure the object you&#8217;ve got will answer the methods you&#8217;re about to use, so what difference does a null check make?</p>
<p>So let&#8217;s write some awesome collaboration tests tests and get cracking!</p>
<p>You should subscribe to my <a href="http://feeds.feedburner.com/TheCodeDump"><span style="color: #000000;">feed</span></a> and follow me on <a href="http://twitter.com/avivby"><span style="color: #000000;">twitter</span></a>!</p>
</div>
<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%2F11%2F14%2Fsay-no-to-null-checks%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.codelord.net%2F2010%2F11%2F14%2Fsay-no-to-null-checks%2F&amp;source=avivby&amp;style=normal&amp;service=bit.ly&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codelord.net/2010/11/14/say-no-to-null-checks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<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>Aviv Ben-Yosef</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&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" 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>Aviv Ben-Yosef</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&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" 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>2</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>Aviv Ben-Yosef</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>Ensuring that you&#8217;re aware of known behaviours is crucial, as it prevents you from looking up issues with software unnecessarily. Of course, you can find these out on the web and it&#8217;s not difficult to test run them if you&#8217;re unsure what they&#8217;ll entail in terms of reversing the process or even repairing a bug or glitch yourself.</p>
<p>Then again, if you&#8217;re reading this tutorial you&#8217;re probably already fairly IT-savvy, so don&#8217;t pay it too much heed. Everything has its own unique digital behavioural patterns, from the <a href="http://shop.o2.co.uk/update/iphone.html">latest O2 uk I phone 4</a> to the newest Alienware MX. It&#8217;s just a case of running checks before you start to ensure that you&#8217;re prepared for any eventuality.</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&amp;service_api=R_6107bfac7c92ddff62b393d1e8b7abbe&amp;b=2" 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>

