<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Generated Tests and TDD</title>
    <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Generated Tests and TDD</title>
      <description>&lt;p&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt; has become quite popular, and many companies are attempting to adopt it.  However, some folks worry that it takes a long time to write all those unit tests and are looking to test-generation tools as a way to decrease that burden.&lt;/p&gt;


	&lt;p&gt;The burden is not insignificant.  FitNesse, an application created using &lt;span class="caps"&gt;TDD&lt;/span&gt;, is comprised of 45,000 lines of Java code, 15,000 of which are unit tests.  Simple math suggests that &lt;span class="caps"&gt;TDD&lt;/span&gt; increases the coding burden by a full third!&lt;/p&gt;


	&lt;p&gt;Of course this is a naive analysis.  The &lt;em&gt;benefits&lt;/em&gt; of using &lt;span class="caps"&gt;TDD&lt;/span&gt; are significant, and far outweigh the burden of writing the extra code.  But that 33% still feels &amp;#8220;extra&amp;#8221; and tempts people to find ways to shrink it without losing any of the benefits.&lt;/p&gt;


	&lt;h1&gt;Test Generators.&lt;/h1&gt;


	&lt;p&gt;Some folks have put their hope in tools that automatically generate tests by inspecting code.  These tools are very clever.  They generate random calls to methods and remember the results.  They can automatically build mocks and stubs to break the dependencies between modules.  They use remarkably clever algorithms to choose their random test data.  They even provide ways for programmers to write plugins that adjust those algorithms to be a better fit for their applications.&lt;/p&gt;


	&lt;p&gt;The end result of running such a tool is a set of &lt;em&gt;observations&lt;/em&gt;.  The tool observes how the instance variables of a class change when calls are made to its methods with certain arguments.  It notes the return values, changes to instance variables, and outgoing calls to stubs and mocks.  And it presents these observations to the user.&lt;/p&gt;


	&lt;p&gt;The user must look through these observations and determine which are correct, which are irrelevant, and which are bugs.  Once the bugs are fixed, these observations can be checked over and over again by re-running the tests.  This is very similar to the record-playback model used by &lt;span class="caps"&gt;GUI&lt;/span&gt; testers.  Once you have registered all the correct observations, you can play the tests back and make sure those observations are still being observed.&lt;/p&gt;


	&lt;p&gt;Some of the tools will even write the observations as JUnit tests, so that you can run them as a standard test suite.  Just like &lt;span class="caps"&gt;TDD&lt;/span&gt;, right?  Well, not so fast&amp;#8230;&lt;/p&gt;


	&lt;p&gt;Make no mistake, tools like this can be very useful.  If you have a wad of untested legacy code, then generating a suite of JUnit tests that verifies some portion of the behavior of that code can be a great boon!&lt;/p&gt;


	&lt;h2&gt;The Periphery Problem&lt;/h2&gt;


On the other hand, no matter how clever the test generator is, the tests it generates will always be more naive than the tests that a human can write.  As a simple example of this, I have tried to generate tests for the bowling game program using two of the better known test generation tools.  The interface to the Bowling Game looks like this:
&lt;code&gt;&lt;pre&gt;
  public class BowlingGame {
    public void roll(int pins) {...}
    public int score() {...}
  }
&lt;/pre&gt;&lt;/code&gt;
The idea is that you call roll each time the balls gets rolled, and you call score at the end of the game to get the score for that game.  

	&lt;p&gt;The test generators could not randomly generate valid games.  It&amp;#8217;s not hard to see why.  A valid game is a sequence of between 12 and 21 rolls, all of which must be integers between 0 and 10.  What&amp;#8217;s more, within a given frame, the sum of rolls cannot exceed 10.  These constraints are just too tight for a random generator to achieve within the current age of the universe.&lt;/p&gt;


	&lt;p&gt;I could have written a plugin that guided the generator to create valid games; but such an algorithm would embody much of the logic of the BowlingGame itself, so it&amp;#8217;s not clear that the economics are advantageous.&lt;/p&gt;


	&lt;p&gt;To generalize this, the test generators have trouble getting &lt;em&gt;inside&lt;/em&gt; algorithms that have any kind of protocol, calling sequence, or state semantics.  They can generate tests around the &lt;em&gt;periphery&lt;/em&gt; of the classes; but can&amp;#8217;t get into the guts without help.&lt;/p&gt;


	&lt;h2&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt;?&lt;/h2&gt;


	&lt;p&gt;The real question is whether or not such generated tests help you with Test Driven Development.  &lt;span class="caps"&gt;TDD&lt;/span&gt; is the act of using tests as a way to drive the development of the system.  You write unit test code first, and then you write the application code that makes that code pass.  Clearly generating tests from existing code violates that simple rule.  So in some philosophical sense, using test generators is &lt;em&gt;not&lt;/em&gt; TDD.  But who cares so long as the tests get written, right?  Well, hang on&amp;#8230;&lt;/p&gt;


	&lt;p&gt;One of the reasons that &lt;span class="caps"&gt;TDD&lt;/span&gt; works so well is that it is similar to the accounting practice of dual entry bookkeeping.  Accountants make every entry twice; once on the credit side, and once on the debit side.  These two entries follow separate mathematical pathways. In the end a magical subtraction yields a zero if all the entries were made correctly.&lt;/p&gt;


	&lt;p&gt;In &lt;span class="caps"&gt;TDD&lt;/span&gt;, programmers state their intent twice; once in the test code, and again in the production code.  These two statements of &lt;em&gt;intent&lt;/em&gt; verify each other.  The tests, test the intent of the code, and the code tests the intent of the tests.  This works because it is a &lt;em&gt;human&lt;/em&gt; that makes both entries!  The human must state the intent twice, but in two complementary forms.  This vastly reduces many kinds of errors; as well as providing significant insight into improved design.&lt;/p&gt;


	&lt;p&gt;Using a test generator breaks this concept because the generator writes the test using the production code as input.  The generated test is not a human restatement, it is an automatic translation.  The human states intent only once, and therefore does not gain insights from restatement, nor does the generated test check that the &lt;em&gt;intent&lt;/em&gt; of the code was achieved.  It is true that the human must verify the observations, but compared to &lt;span class="caps"&gt;TDD&lt;/span&gt; that is a far more passive action, providing far less insight into defects, design and intent.&lt;/p&gt;


	&lt;p&gt;I conclude from this that automated test generation is neither equivalent to &lt;span class="caps"&gt;TDD&lt;/span&gt;, nor is it a way to make &lt;span class="caps"&gt;TDD&lt;/span&gt; more efficient.  What you gain by trying to generate the 33% test code, you lose in defect elimination, restatement of intent, and design insight. You also sacrifice depth of test coverage, because of the periphery problem.&lt;/p&gt;


	&lt;p&gt;This does not mean that test generators aren&amp;#8217;t useful.  As I said earlier, I think they can help to partially characterize a large base of legacy code.  But these tools are not &lt;span class="caps"&gt;TDD&lt;/span&gt; tools. The tests they generate are not equivalent to tests written using &lt;span class="caps"&gt;TDD&lt;/span&gt;.  And many of the benefits of &lt;span class="caps"&gt;TDD&lt;/span&gt; are not achieved through test generation.&lt;/p&gt;</description>
      <pubDate>Thu, 10 Jan 2008 13:59:30 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:8528afa6-7e1b-406d-ab72-18557ff0912c</guid>
      <author>Uncle Bob</author>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd</link>
      <category>Uncle Bob's Blatherings</category>
      <category>Agile Methods</category>
    </item>
    <item>
      <title>"Generated Tests and TDD" by grad school personal statement</title>
      <description>&lt;p&gt;I am absolutely amazed at how terrific the stuff is on this site. I have saved this webpage and I truly intend on visiting the site in the upcoming days. Keep up the excellent work!&lt;/p&gt;</description>
      <pubDate>Fri, 23 Dec 2011 09:37:11 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:434f1491-4800-43f3-a253-53a2876009e6</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-190856</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by christian louboutin</title>
      <description>&lt;p&gt;The professional design make you foot more comfortable. Even more tantalizing,this pattern make your legs look as long as you can,it will make you looked more attractive.Moveover,it has reasonable price.If you are a popular woman,do not miss it.&lt;/p&gt;


	&lt;p&gt;Technical details of Christian Louboutin Velours Scrunch Suede Boots Coffee:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;Color: Coffee
Material: Suede
4(100mm) heel
Signature red sole x&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Fashion, delicate, luxurious Christian louboutins shoes on sale, one of its series is Christian Louboutin Tall Boots, is urbanism collocation. This Christian louboutins shoes design makes people new and refreshing. Red soles shoes is personality, your charm will be wonderful performance.&lt;/p&gt;</description>
      <pubDate>Thu, 03 Nov 2011 09:11:08 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4ae984ac-1912-486f-aed3-ca48f54e17bb</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-167613</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Ashley Bowling</title>
      <description>&lt;p&gt;A fool and his money are soon parted
A friend in need is a friend indeed
A golden key can open any door&lt;/p&gt;</description>
      <pubDate>Sun, 16 Oct 2011 01:46:56 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4ad3634e-a296-44f5-812c-9b8e8a558242</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-157315</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by african Mango dr oz</title>
      <description>&lt;p&gt;Cloudsourcing combines on-demand business process outsourcing (BPO) with crowdsourcing technologies to enable companies to purchase quality BPO services on-demand through a pay-per-use model.&lt;/p&gt;</description>
      <pubDate>Tue, 27 Sep 2011 12:02:02 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:058ddeda-ae40-4aef-b6e1-b65ccb29bc0e</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-146188</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Diablo3</title>
      <description>&lt;p&gt;hmm ,i&amp;#8217;m not sure if this is what i&amp;#8217;m looking for but anyway this is interresting and could be useful some day,thanks for taking time to write such cool stuff&lt;/p&gt;</description>
      <pubDate>Wed, 14 Sep 2011 14:34:03 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:cae47ac0-cf19-4502-8974-cd9b824ad847</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-140298</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by beats by dr dre headphones</title>
      <description>&lt;p&gt;&lt;a href="http://www.drebeatsstudio.com/beats-by-dr-dre-studio-c-3.html" rel="nofollow"&gt;Beats by dr dre studio&lt;/a&gt; with look after talk in white. extra attributes on &lt;a href="http://www.drebeatsstudio.com/monster-beats-by-dr-dre-pro-headphones-black-p-15.html" rel="nofollow"&gt;Monster Beats By Dr. Dre Pro Headphones Black&lt;/a&gt; a specific tri-fold design and design and carrying circumstance which make for compact and uncomplicated safe-keeping when not in use. &lt;a href="http://www.drebeatsstudio.com/beats-by-dr-dre-solo-c-5.html" rel="nofollow"&gt;Beats by dr dre solo&lt;/a&gt; .&lt;/p&gt;</description>
      <pubDate>Wed, 08 Jun 2011 21:38:32 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:d893e61d-75a5-420a-9f55-ea8ab1d1ee2b</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-109206</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Jewellery</title>
      <description>&lt;p&gt;i am happy for your responses&lt;/p&gt;</description>
      <pubDate>Sat, 04 Jun 2011 05:33:07 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:64968f79-350e-4bef-90b8-149a3e0d75ac</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-108023</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Discont Louis Vuitton Scarves</title>
      <description>&lt;p&gt;Thank you for sharing information :-&lt;/p&gt;</description>
      <pubDate>Tue, 17 May 2011 21:18:29 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:50086623-d4ce-4338-aae9-f78bce95b7dd</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-101033</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by f350 leveling kit</title>
      <description>&lt;p&gt;Thank you for sharing information :-)&lt;/p&gt;</description>
      <pubDate>Thu, 12 May 2011 23:31:20 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:22a73893-d7b7-49ed-91da-c98a125a0f8a</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-99123</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by leveling kit f250</title>
      <description>&lt;p&gt;Cool website very informative :-)&lt;/p&gt;</description>
      <pubDate>Thu, 12 May 2011 23:30:58 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f5845691-7ab3-4085-9a37-fa3c04d834be</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-99122</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by leveling kit ford</title>
      <description>&lt;p&gt;Thanks you, its very formative :-)&lt;/p&gt;</description>
      <pubDate>Thu, 12 May 2011 23:30:40 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:6c86ca2b-871f-4464-804d-84ce7b8e0387</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-99121</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by ford leveling kit</title>
      <description>&lt;p&gt;I always read your blogs and I like it. thank you :-)&lt;/p&gt;</description>
      <pubDate>Thu, 12 May 2011 23:30:24 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b3a0ed52-926e-4cd4-841b-f1f55c2a0385</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-99120</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by okey oyunu oyna </title>
      <description>&lt;p&gt;thank you very much&lt;/p&gt;


	&lt;p&gt;internette g&#246;r&#252;nt&#252;l&#252; olarak &lt;a href="http://www.okeyoyunu-oyna.com" rel="nofollow"&gt;okey oyunu oyna&lt;/a&gt;, ger&#231;ek kisilerle tanis,
 turnuva heyecanini yasa.&lt;/p&gt;</description>
      <pubDate>Wed, 27 Apr 2011 12:10:39 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:5415dcf2-f6da-4b52-880d-fd567cf80c91</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-91819</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by dory</title>
      <description>&lt;p&gt;Useful information will I follow your posts. &lt;a href="hallohi.net" rel="nofollow"&gt;Social Network&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 03 Apr 2011 18:45:36 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:0faff108-5306-48e3-b69b-866c5b9cbbd4</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-78902</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by SEO Firm India</title>
      <description>&lt;p&gt;Excellently written article, if only all blogger offered the same content as you, the internet would be a much better place. Please keep it up!&lt;/p&gt;</description>
      <pubDate>Fri, 18 Mar 2011 13:12:50 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9b1e1227-2e04-46ef-a04d-db90b4e9970a</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-73651</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Sunglass</title>
      <description>&lt;p&gt;Buy $10 Replica Designer Sunglasses with 3-day FREE SHIPPING&lt;/p&gt;</description>
      <pubDate>Wed, 09 Mar 2011 05:19:26 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:26020579-4c78-47a3-9623-cdf1ec743228</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-70926</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by cable ties</title>
      <description>&lt;p&gt;great effort exerted.&lt;/p&gt;</description>
      <pubDate>Thu, 03 Mar 2011 05:30:14 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:a6028c7d-50dc-44f8-a1c9-1385114d831b</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-68714</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Tenant Screening</title>
      <description>&lt;p&gt;Another important use of TDD is to ensure that you let user stories drive the requirements. In this case, you&#8217;d write a user story (e.g. using FIT or the RSpec Story Runner) first, then write a view spec, then a controller spec, then finally a model spec if required.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Feb 2011 15:25:02 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:fbdf3d2e-f947-4724-9f6f-66412260392d</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-63913</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Criminal Records</title>
      <description>&lt;p&gt;Some of the tools will even write the observations as JUnit tests, so that you can run them as a standard test suite.&lt;/p&gt;</description>
      <pubDate>Fri, 11 Feb 2011 12:31:04 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:c2879588-b291-4405-ba01-5f35f3bd0141</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-62027</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Low Carb Meals</title>
      <description>&lt;p&gt;It is proven time and time again that information&#8217;s worth is not the main factor which impacts article&lt;/p&gt;


	&lt;p&gt;promotion results.&lt;/p&gt;</description>
      <pubDate>Sun, 30 Jan 2011 23:43:26 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d9ba6954-eda7-47b5-9247-74eee5ae9dc7</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-60397</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by Criminal Check</title>
      <description>&lt;p&gt;The tests they generate are not equivalent to tests written using TDD.&lt;/p&gt;</description>
      <pubDate>Thu, 27 Jan 2011 17:01:51 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:431c95dd-8c49-4aa9-8018-c6b517a9076a</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-59876</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by axial fan</title>
      <description>&lt;p&gt;This article is very usefull for me! I can see that you are putting a lots of efforts into your blog. I will keep watching in your blog, thanks.&lt;/p&gt;</description>
      <pubDate>Thu, 27 Jan 2011 01:03:09 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:ef49db10-0edc-4350-b841-fffc4eb0a7cb</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-59725</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by iPad PDF Transfer for Mac</title>
      <description>&lt;p&gt;I really like this essay. Thank you for writing it so seriously. I want to recommend it for my friends strongly. iPad PDF Transfer for Mac can help you transfer ebooks in PDF format from ipad to mac/iTunes.&lt;/p&gt;</description>
      <pubDate>Mon, 24 Jan 2011 02:30:45 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:bb034855-deea-48c0-8a67-5215759c4eb3</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-58971</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by iPad to mac transfer</title>
      <description>&lt;p&gt;Thanks for shareing! I agree with you. The artical improve me so much! I will come here frequently. iPad to Mac Transfer lets you transfer music, movie, photo, ePub, PDF, Audiobook, Podcast and TV Show from iPad to Mac or iPad to iTunes.&lt;/p&gt;</description>
      <pubDate>Mon, 24 Jan 2011 02:27:10 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:9a83013c-3fd4-4cad-bc84-922486f416ab</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-58962</link>
    </item>
    <item>
      <title>"Generated Tests and TDD" by http://www.blacktowhiteiphone4.com</title>
      <description>&lt;p&gt;Enjoy the christmas time and enjoy the hottest &lt;a href="http://www.blacktowhiteiphone4.com" rel="nofollow"&gt;white iphone 4&lt;/a&gt;. All you need to do is the white iphone 4 conversion kit home. &lt;br&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 23 Dec 2010 01:48:51 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:01404153-8413-41d0-8015-74646ae8966d</guid>
      <link>http://blog.objectmentor.com/articles/2008/01/10/generated-tests-and-tdd#comment-51278</link>
    </item>
  </channel>
</rss>

