<?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: Tag TDD</title>
    <link>http://blog.objectmentor.com/articles/tag/tdd</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>TDD is how I do it, not what I do</title>
      <description>&lt;blockquote&gt;
&amp;#8220;Do not seek to follow in the footsteps of the men of old; seek what they sought.&amp;#8221; ~Basho
&lt;/blockquote&gt;

	&lt;p&gt;That quote resonates with me. I happend across that a few days after co-teaching 
an &amp;#8220;advanced &lt;span class="caps"&gt;TDD&lt;/span&gt;&amp;#8221; course with Uncle Bob. One of the recurring themes during the week
was that &lt;span class="caps"&gt;TDD&lt;/span&gt; is a &amp;#8220;how&amp;#8221; not a &amp;#8220;what&amp;#8221;. It&amp;#8217;s important to remember that &lt;span class="caps"&gt;TDD&lt;/span&gt; is not the
goal, the&lt;i&gt; &lt;b&gt;results&lt;/b&gt;&lt;/i&gt; of successfully applying &lt;span class="caps"&gt;TDD&lt;/span&gt; are.&lt;/p&gt;


	&lt;p&gt;What are those results?&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;You could end up writing less code to accomplish the same thing&lt;/li&gt;
		&lt;li&gt;You might write better code that is less-coupled and more maleable&lt;/li&gt;
		&lt;li&gt;The code tends to be testable because, well, it IS tested&lt;/li&gt;
		&lt;li&gt;The coverage of your tests will be such that making significant changes will not be too risky&lt;/li&gt;
		&lt;li&gt;The number of defects should be quite low&lt;/li&gt;
		&lt;li&gt;The tests serve as excellent exampls of how to use the various classes in your solution&lt;/li&gt;
		&lt;li&gt;Less &amp;#8220;just in case&amp;#8221; code written, which typically doesn&amp;#8217;t work in those cases that they targeted&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Right now I do not know of a better way to accomplish all of these results more effectively
than practicing &lt;span class="caps"&gt;TDD&lt;/span&gt;. Even so, this does not elevate &lt;span class="caps"&gt;TDD&lt;/span&gt; from a &amp;#8220;how&amp;#8221; to a &amp;#8220;what.&amp;#8221; 
&lt;span class="caps"&gt;TDD&lt;/span&gt; remains a technique to accomplish thigns I value. It is not a self-justifying
practice. If someone asks me &amp;#8220;why do we do it this way&amp;#8221;, saying something like
&amp;#8220;we practice &lt;span class="caps"&gt;TDD&lt;/span&gt;&amp;#8221; or &amp;#8220;well you don&amp;#8217;t understand &lt;span class="caps"&gt;TDD&lt;/span&gt;&amp;#8221; is not a good answer.&lt;/p&gt;


We had an interesting result during that class. One group was practicing Bob&amp;#8217;s three rules of &lt;span class="caps"&gt;TDD&lt;/span&gt; (paraphrased); 
	&lt;ul&gt;
	&lt;li&gt;Write no production code without failing tests&lt;/li&gt;
		&lt;li&gt;Write only enough test code so that it fails (not compiling is failing)&lt;/li&gt;
		&lt;li&gt;Write only enough production code to get your tests to pass.&lt;/li&gt;
	&lt;/ul&gt;


But they ended up with a bit of a mess. Following the three rules wasn&amp;#8217;t enough. These rules are guiding principles, but those three rules mean nothing if you forget about clean code, refactoring and basic design principles (here are a few):
	&lt;ul&gt;
	&lt;li&gt;S.O.L.I.D.&lt;/li&gt;
		&lt;li&gt;F.I.R.S.T.&lt;/li&gt;
		&lt;li&gt;Separation of Concerns (Square Law of Computation)&lt;/li&gt;
		&lt;li&gt;Coupling/Cohesion&lt;/li&gt;
		&lt;li&gt;Protected Variation&lt;/li&gt;
		&lt;li&gt;...&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt; is a means to an end but it is the end we care about. What is that end? 
Software that has few defects and is easy to change. Tests give us that. Not 
testing generally does not give us that. And testing in a common &amp;#8220;QA over the wall&amp;#8221; configuration typically does not cut it.&lt;/p&gt;


	&lt;p&gt;Since I do not know how to so easily produce those results in any other way. &lt;span class="caps"&gt;TDD&lt;/span&gt; becomes the defacto means of implementation for me. That doesn&amp;#8217;t mean I should turn a blind eye to new ways of doing things. In lieu of any such information, however, I&amp;#8217;ll pick &lt;span class="caps"&gt;TDD&lt;/span&gt; as a starting point. This is still a &amp;#8220;how&amp;#8221; and not a &amp;#8220;what&amp;#8221;.&lt;/p&gt;


It turns out that for me there are several tangible benefits I&amp;#8217;ve personally 
experienced from practicing &lt;span class="caps"&gt;TDD&lt;/span&gt;:
	&lt;ul&gt;
	&lt;li&gt;Increased confidence in the code I produce (even more than when I was simply test infected)&lt;/li&gt;
		&lt;li&gt;Less worrying about one-off conditions and edge cases. I&amp;#8217;ll get to them and as I think about then, they become tests&lt;/li&gt;
		&lt;li&gt;Fun&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Fun?&lt;/p&gt;


Yes I wrote fun. There are several aspects of this:
	&lt;ul&gt;
	&lt;li&gt;I seem to produce demonstrable benefits sooner&lt;/li&gt;
		&lt;li&gt;I actually do more analysis throughout&lt;/li&gt;
		&lt;li&gt;I get to do more OO programming&lt;/li&gt;
	&lt;/ul&gt;


&lt;h4&gt;Demonstrable Benefits Sooner&lt;/h4&gt;
Since I focus on one test at a time, I frequently get back to running tests. I&amp;#8217;m able to see results sooner. Sure, those results are sometimes disjoint and piecemeal, but over time they organically grow into something useful. I really enjoy teaching a class and moving from a trivial test to a suite a tests that together have caused what students can see is a tangible implementation of something complex.

&lt;h4&gt;More Analysis&lt;/h4&gt;
Analysis means to break into constituent parts. When I practice &lt;span class="caps"&gt;TDD&lt;/span&gt;, I think about some end (say a user story or a scenario) then I think about a small part of that overall work and tackle it. In the act of getting to a test, I&amp;#8217;m doing enough analysis to figure out at least some of the parts of what I&amp;#8217;m trying to do. I&amp;#8217;m breaking my goal into a parts, that&amp;#8217;s a pretty good demonstration of analysis.

&lt;h4&gt;More OO&lt;/h4&gt;
I like polymorphism. I like lots of shallow, but broad hierarchies. 
I prefer delegation to inheritance. But often, the things I&amp;#8217;m writing 
don&amp;#8217;t need a lot of this &amp;#8211; or so it might seem.

	&lt;p&gt;When I try to create a good unit test, much of what I&amp;#8217;m doing is trying 
to figure out how the effect I&amp;#8217;m shooting for can be isolated 
to make the test fast, independent, reliable &amp;#8230; To do so, I 
make heavy use of test doubles. Sometimes I hand-roll them, sometimes 
I use mocking libraries. I&amp;#8217;ve event used &lt;span class="caps"&gt;AOP&lt;/span&gt; frameworks, but not nearly as extensively.&lt;/p&gt;


	&lt;p&gt;Doing all of this allows me to use polymorphism more often. And that&amp;#8217;s fun.&lt;/p&gt;


&lt;h3&gt;Conclusion&lt;/h3&gt;
Am I wasting time writing all of these tests? Is my enjoyment of my work
an indication that I might be wasting the time of my product owner?

	&lt;p&gt;Those are good questions. And these are things you might want to ask yourself.&lt;/p&gt;


Personally, I&amp;#8217;m pretty sure I&amp;#8217;m not wasting anyone&amp;#8217;s time for several reasons:
	&lt;ul&gt;
	&lt;li&gt;The product owner is keeping me focused on things that add value&lt;/li&gt;
		&lt;li&gt;Short iterations keep me reigned in&lt;/li&gt;
		&lt;li&gt;I&amp;#8217;m only doing as much as necessary to get the stories for an iteration implemented&lt;/li&gt;
		&lt;li&gt;The tests I&amp;#8217;m writing stay passing, run quickly and over time remain (become) maintainable&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Even so, since &lt;span class="caps"&gt;TDD&lt;/span&gt; is a how and not a what, I still need to keep asking myself
if the work I&amp;#8217;m doing is moving us towards a working solution that will be
maintainable during its lifetime.&lt;/p&gt;


	&lt;p&gt;I think it is. What about you?&lt;/p&gt;</description>
      <pubDate>Mon, 21 Jul 2008 14:32:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b4795a7f-9544-422c-bb60-8cf16917afbd</guid>
      <author>Brett Schuchert</author>
      <link>http://blog.objectmentor.com/articles/2008/07/21/tdd-is-how-i-do-it-not-what-i-do</link>
      <category>Schuchert's Scattered Synapses </category>
      <category>TDD</category>
      <category>how</category>
      <category>versus</category>
      <category>what</category>
    </item>
    <item>
      <title>Observations on Test-Driving User Interfaces</title>
      <description>&lt;p&gt;Test driving user interface development has always been a challenge. Recently, I&amp;#8217;ve worked with two projects where most of the work has been on the user-interface components.&lt;/p&gt;


	&lt;p&gt;The first project is using Adobe Flex to create a rich interface. The team decided to adopt &lt;a href="http://funfx.rubyforge.org/"&gt;FunFX&lt;/a&gt; for acceptance testing. You write your tests in Ruby, typically using &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt; or &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;FunFX places some constraints on your Flex application. You have to define the &lt;span class="caps"&gt;GUI&lt;/span&gt; objects in &lt;span class="caps"&gt;MXML&lt;/span&gt;, the &lt;span class="caps"&gt;XML&lt;/span&gt;-based file format for Flex applications, rather than ActionScript, and you need to add ids to all elements you want to reference.[1]&lt;/p&gt;


	&lt;p&gt;These are reasonable constraints and the first constraint promotes better quality, in fact. The &lt;span class="caps"&gt;MXML&lt;/span&gt; format is more succinct (despite the &lt;span class="caps"&gt;XML&lt;/span&gt; &amp;#8220;noise&amp;#8221;) and declarative than ActionScript code. This is almost always true of UI code in most languages (with notable exceptions&amp;#8230;). Declarative &lt;em&gt;vs.&lt;/em&gt; imperative code tends to improve quality because less code means fewer bugs, less to maintain, and it frees the implementor of the declarative &amp;#8220;language&amp;#8221; to pick the best implementation strategies, optimizations, &lt;em&gt;etc.&lt;/em&gt; This characteristic is typical of Functional Languages and well-designed Domain Specific Languages, as well.&lt;/p&gt;


	&lt;p&gt;I don&amp;#8217;t think you can underestimate the benefit of writing &lt;strong&gt;less&lt;/strong&gt; code. I see too many teams whose problems would diminish considerably if they just got rid of duplication and learned to be &lt;em&gt;concise&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;The second project is a wiki-based application written in Java. To make deployment as simple as possible, the implementors avoided the Servlet &lt;span class="caps"&gt;API&lt;/span&gt; (no need to install Tomcat, &lt;em&gt;etc.&lt;/em&gt;) and rolled their own web server and page rendering components. (I&amp;#8217;m not sure I would have made these decisions myself, but I don&amp;#8217;t think they are bad, either&amp;#8230;)&lt;/p&gt;


	&lt;p&gt;The rendering components are object-oriented and use a number of design patterns, such as page factories with builder objects that reflect the &amp;#8220;widgets&amp;#8221; in the UI, &lt;span class="caps"&gt;HTML&lt;/span&gt; tags, &lt;em&gt;etc.&lt;/em&gt; This approach makes the UI very testable with JUnit and &lt;a href="http://www.fitnesse.org"&gt;FitNesse&lt;/a&gt;. In fact, the development process was a model of test-driven development.&lt;/p&gt;


	&lt;p&gt;However, the final result is flawed!  It is much too difficult to change the &lt;em&gt;look and feel&lt;/em&gt; of the application, which is essential for most UI&amp;#8217;s, especially web UI&amp;#8217;s. The project made the wrong tradeoffs; the design choices met the requirements of &lt;span class="caps"&gt;TDD&lt;/span&gt; very well, but they made maintenance and enhancement expensive and tedious. The application is now several years old and it has become dated, because of the expense of &amp;#8220;refreshing&amp;#8221; the &lt;em&gt;look and feel&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;What should have been done? These days, most dynamic web UI&amp;#8217;s are built with templating engines, of which there are many in the most common programming languages. Pages defined in a templating engine are very declarative, except for the special tags where behavior is inserted. The pages are easy to change. It is mostly obvious where a particular visual element is generated, since most of the &amp;#8220;tags&amp;#8221; in the template look exactly like the tags in the rendered page. &amp;#8220;Declarative&amp;#8221; templates, like good &lt;span class="caps"&gt;DSL&lt;/span&gt;&amp;#8217;s, can be read, understood, and even edited by the &lt;em&gt;stakeholders&lt;/em&gt;, in this case the graphical designers.&lt;/p&gt;


	&lt;p&gt;But how do you test these page templates? When test-driving UI&amp;#8217;s it is important to decide what to test and what &lt;strong&gt;not&lt;/strong&gt; to test. The general rule for &lt;span class="caps"&gt;TDD&lt;/span&gt; is to &lt;em&gt;test anything that can break&lt;/em&gt;.  The corollary, especially relevant for UI&amp;#8217;s, is &lt;em&gt;don&amp;#8217;t test anything when you don&amp;#8217;t care if it changes&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;It is usually the &lt;em&gt;dynamic behavior&lt;/em&gt; of the UI that can break and should be tested. Templating engines provide special tags for inserting dynamic behavior in the underlying language (Java, Ruby, &lt;em&gt;etc.&lt;/em&gt;). &lt;em&gt;This&lt;/em&gt; is what you should test. It is usually best to keep the &lt;em&gt;scripts&lt;/em&gt; in these tags as small as possible; the scripts just delegate to code, which can be test-driven in the usual way.&lt;/p&gt;


	&lt;p&gt;I see too many UI tests that compare long strings of &lt;span class="caps"&gt;HTML&lt;/span&gt;. These tests break whenever someone makes a minor &lt;em&gt;look and feel&lt;/em&gt; or other inconsequential change. Part of the art of &lt;span class="caps"&gt;UI TDD&lt;/span&gt; is knowing how to test just what can break and nothing more. In the second project, incidental changes to the UI break tests that should be &lt;em&gt;agnostic&lt;/em&gt; to such changes.&lt;/p&gt;


	&lt;p&gt;To conclude, keep your UI&amp;#8217;s as &lt;em&gt;declarative&lt;/em&gt; as you can. Only test the &amp;#8220;declarations&amp;#8221; (&lt;i&gt;e.g.&lt;/i&gt;, templates) in areas where they might &lt;em&gt;break&lt;/em&gt;, meaning if it changes, it&amp;#8217;s a bug. You&amp;#8217;ll get the full benefits of &lt;span class="caps"&gt;TDD&lt;/span&gt; and the freedom to change the UI easily and frequently, as needed.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; Disclaimer: my information on FunFX is second hand, so I might not have the details exactly correct; see the &lt;a href="http://funfx.rubyforge.org/"&gt;FunFX&lt;/a&gt; documentation for details.&lt;/p&gt;</description>
      <pubDate>Sun, 22 Jun 2008 16:52:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:107f8948-2e28-48d7-a495-85d56801b376</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2008/06/22/observations-on-test-driving-user-interfaces</link>
      <category>Dean's Deprecations</category>
      <category>Testing GUIs</category>
      <category>Design Principles</category>
      <category>TDD</category>
      <category>gui</category>
      <category>declarative</category>
      <category>functional</category>
      <category>design</category>
    </item>
    <item>
      <title>TDD on Three Index Cards</title>
      <description>&lt;p&gt;I had the opportunity to talk to a fellow who missed part of a class on &lt;span class="caps"&gt;TDD&lt;/span&gt;. I told him that I could give him a 15-minute overview, and give him all the essentials of &lt;span class="caps"&gt;TDD&lt;/span&gt; on three index cards.&lt;/p&gt;


	&lt;p&gt;Yes, I know that volumes have been written about &lt;span class="caps"&gt;TDD&lt;/span&gt; and &lt;span class="caps"&gt;BDD&lt;/span&gt;, and that it&amp;#8217;s a large topic with many many branches of application, but I didn&amp;#8217;t have time for that. I had time for three index cards.  I figure that an index card is a token, and it represents a conversation, and that one can always dig deeper later.&lt;/p&gt;


	&lt;p&gt;They looked more or less like this:&lt;/p&gt;


&lt;hr&gt;
Card 1: Uncle Bob&amp;#8217;s Three Laws (Object Mentor)
&lt;ol&gt;
&lt;li&gt;Write no production code except to pass a failing test.&lt;/li&gt;
&lt;li&gt;Write only enough of a test to demonstrate a failure.&lt;/li&gt;
&lt;li&gt;Write only enough production code to pass the test.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr&gt;
Card 2: &lt;span class="caps"&gt;FIRST&lt;/span&gt; Principles (Brett and Tim at Object Mentor)
&lt;ul&gt;
&lt;li&gt;&lt;i&gt;F&lt;/i&gt;ast: Mind-numbingly fast, as in hundreds or thousands per second.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;I&lt;/i&gt;solated: The test isolates a fault clearly.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;R&lt;/i&gt;epeatable: I can run it repeatedly and it will pass or fail the same way each time.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;S&lt;/i&gt;elf-verifying: The test is unambiguously pass-fail.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;T&lt;/i&gt;imely: Produced in lockstep with tiny code changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr&gt;
Card 3: Flow (using the famous three-node circle diagram) &amp;#8211; origin unknown.
&lt;ul&gt;
&lt;li&gt;Red: test fails&lt;/li&gt;
&lt;li&gt;Green: test passes&lt;/li&gt;
&lt;li&gt;Refactor: clean code and tests&lt;/li&gt;
&lt;/ul&gt;

	&lt;p&gt;Sure there is plenty more, but I didn&amp;#8217;t know how I could provide significantly less. As is, I&amp;#8217;m pretty happy with the exercise. Now I am wondering if I couldn&amp;#8217;t produce most of the important information I wish to convey as a series of index cards. Would that be cool or what?&lt;/p&gt;</description>
      <pubDate>Thu, 06 Mar 2008 19:39:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a7002e7d-5f30-481f-8792-20f01b2e731f</guid>
      <author>Tim Ottinger</author>
      <link>http://blog.objectmentor.com/articles/2008/03/06/tdd-on-three-index-cards</link>
      <category>Tim's Tepid Torrent</category>
      <category>testing</category>
      <category>TDD</category>
      <category>three</category>
      <category>index</category>
      <category>cards</category>
      <category>reminders</category>
      <category>simplified</category>
    </item>
    <item>
      <title>Unit Testing C and C++ ... with Ruby and RSpec!</title>
      <description>&lt;p&gt;If you&amp;#8217;re writing C/C&amp;#043;&amp;#043; code, it&amp;#8217;s natural to write your unit tests in the same language (or use C&amp;#043;&amp;#043; for your C test code). All the well-known unit testing tools take this approach.&lt;/p&gt;


	&lt;p&gt;I think we can agree that neither language offers the best developer productivity among all the language choices out there. Most of us use either language because of perceived performance requirements, institutional and industry tradition, &lt;em&gt;etc.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;There&amp;#8217;s growing interest, however, in mixing languages, tools, and &lt;em&gt;paradigms&lt;/em&gt; to get the best tool for a particular job. &amp;lt;shameless-plug&amp;gt;I&amp;#8217;m giving a talk March 7&lt;sup&gt;th&lt;/sup&gt; at &lt;a href="https://www.cmpevents.com/SDw8/a.asp?option=C&amp;#38;V=11&amp;#38;SessID=6102"&gt;SD West&lt;/a&gt; on this very topic, called &lt;a href="https://www.cmpevents.com/SDw8/a.asp?option=C&amp;#38;V=11&amp;#38;SessID=6102"&gt;Polyglot and Poly-Paradigm Programming&lt;/a&gt; &amp;lt;/shameless-plug&amp;gt;.&lt;/p&gt;


	&lt;p&gt;So, why not use a more productive language for your C or C&amp;#043;&amp;#043; unit tests? You have more freedom in your development chores than what&amp;#8217;s required for production. Why not use Ruby&amp;#8217;s &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;, a &lt;a href="http://behaviour-driven.org/"&gt;Behavior-Driven Development&lt;/a&gt; tool for acceptance and unit testing? Or, you could use Ruby&amp;#8217;s version of &lt;a href="http://www.junit.org"&gt;JUnit&lt;/a&gt;, called &lt;a href="http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt;. The hard part is integrating Ruby and C/C&amp;#043;&amp;#043;. If you&amp;#8217;ve been looking for an excuse to bring Ruby (or Tcl or Python or Java or&amp;#8230;) into your C/C&amp;#043;&amp;#043; environment, starting with development tasks is usually the path of least resistance.&lt;/p&gt;


	&lt;p&gt;I did some experimenting over the last few days to integrate &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;  using &lt;a href="http://www.swig.org"&gt;&lt;span class="caps"&gt;SWIG&lt;/span&gt;&lt;/a&gt; (Simplified Wrapper and Interface Generator), a tool for bridging libraries written in C and C&amp;#043;&amp;#043; to other languages, like Ruby. The &lt;a href="http://www.swig.org/Doc1.3/Ruby.html"&gt;Ruby section&lt;/a&gt; of the &lt;span class="caps"&gt;SWIG&lt;/span&gt; manual was very helpful.&lt;/p&gt;


	&lt;h2&gt;My Proof-of-Concept Code&lt;/h2&gt;


	&lt;p&gt;Here is a zip file of my experiment: &lt;a href="http://blog.objectmentor.com/files/rspec_for_cpp.zip" title="rspec_for_cpp.zip"&gt;rspec_for_cpp.zip&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;This is far from a complete and working solution, but I think it shows promise. See the &lt;strong&gt;Current Limitations&lt;/strong&gt; section below for details.&lt;/p&gt;


	&lt;p&gt;Unzip the file into a directory. I&amp;#8217;ll assume you named it &lt;code&gt;rspec_for_cpp&lt;/code&gt;. You need to have &lt;code&gt;gmake&lt;/code&gt;, &lt;code&gt;gcc&lt;/code&gt;, &lt;span class="caps"&gt;SWIG&lt;/span&gt; and Ruby installed, along with the RSpec &amp;#8220;gem&amp;#8221;. Right now, it only builds on &lt;span class="caps"&gt;OS X&lt;/span&gt; and Linux (at least the configurations on my machines running those OS&amp;#8217;s &amp;#8211; see the discussion below). To run the build, use the following commands:&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        $ cd rspec_for_cpp/cpp
        $ make 
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;You should see it finish with the lines&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        ( cd ../spec; spec *_spec.rb )
        .........

        Finished in 0.0***** seconds

        9 examples, 0 failures
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Congratulations, you&amp;#8217;ve just tested some C and C&amp;#043;&amp;#043; code with RSpec! (Or, if you didn&amp;#8217;t succeed, see the notes in the &lt;code&gt;Makefile&lt;/code&gt; and the discussion below.)&lt;/p&gt;


	&lt;h2&gt;The Details&lt;/h2&gt;


	&lt;p&gt;I&amp;#8217;ll briefly walk you through the files in the zip and the key steps required to make it all work.&lt;/p&gt;


	&lt;h3&gt;&lt;code&gt;cexample.h&lt;/code&gt;&lt;/h3&gt;


	&lt;p&gt;Here is a simple C header file.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        /* cexample.h */
        #ifndef CEXAMPLE_H
        #define CEXAMPLE_H
        #ifdef __cplusplus
         extern "C" {
        #endif
        char* returnString(char* input);
        double returnDouble(int input);
        void  doNothing();

        #ifdef __cplusplus
         }
        #endif
        #endif
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Of course, in a pure C shop, you won&amp;#8217;t need the &lt;code&gt;#ifdef __cplusplus&lt;/code&gt; stuff. I found this was essential in my experiment when I mixed C and C&amp;#043;&amp;#043;, as you might expect.&lt;/p&gt;


	&lt;h3&gt;&lt;code&gt;cpp/cexample.c&lt;/code&gt;&lt;/h3&gt;


	&lt;p&gt;Here is the corresponding C source file.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        /* cexample.h */

        char* returnString(char* input) {
            return input;
        }

        double returnDouble(int input) {
            return (double) input;
        }

        void  doNothing() {}
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;h3&gt;&lt;code&gt;cpp/CppExample.h&lt;/code&gt;&lt;/h3&gt;


	&lt;p&gt;Here is a C&amp;#043;&amp;#043; header file.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        #ifndef CPPEXAMPLE_H
        #define CPPEXAMPLE_H

        #include &amp;lt;string&amp;gt;

        class CppExample 
        {
        public:
            CppExample();
            CppExample(const CppExample&amp;#38; foo);
            CppExample(const char* title, int flag);
            virtual ~CppExample();

            const char* title() const;
            void        title(const char* title);
            int         flag() const;
            void        flag(int value);

            static int countOfCppExamples();
        private:
            std::string _title;
            int         _flag;
        };

        #endif
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;h3&gt;&lt;code&gt;cpp/CppExample.cpp&lt;/code&gt;&lt;/h3&gt;


	&lt;p&gt;Here is the corresponding C&amp;#043;&amp;#043; source file.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        #include "CppExample.h" 

        CppExample::CppExample() : _title("") {}
        CppExample::CppExample(const CppExample&amp;#38; foo): _title(foo._title) {}
        CppExample::CppExample(const char* title, int flag) : _title(title), _flag(flag) {}
        CppExample::~CppExample() {}

        const char* CppExample::title() const { return _title.c_str(); }
        void        CppExample::title(const char* name) { _title = name; }

        int  CppExample::flag() const { return _flag; }
        void CppExample::flag(int value) { _flag = value; }

        int CppExample::countOfCppExamples() { return 1; }
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;h3&gt;&lt;code&gt;cpp/example.i&lt;/code&gt;&lt;/h3&gt;


	&lt;p&gt;Typically in &lt;span class="caps"&gt;SWIG&lt;/span&gt;, you specify a &lt;code&gt;.i&lt;/code&gt; file to the &lt;code&gt;swig&lt;/code&gt; command to define the &lt;em&gt;module&lt;/em&gt; that wraps the classes and global functions, which classes and functions to expose to the target language (usually all in our case), and other assorted customization options, which are discussed in the &lt;a href="http://www.swig.org/Doc1.3"&gt;&lt;span class="caps"&gt;SWIG&lt;/span&gt; manual&lt;/a&gt;. I&amp;#8217;ll show the &lt;code&gt;swig&lt;/code&gt; command in a minute. For now, note that I&amp;#8217;m going to generate an &lt;code&gt;example_wrap.cpp&lt;/code&gt; file that will function as the bridge between the languages.&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s my &lt;code&gt;example.i&lt;/code&gt;, where I named the module &lt;code&gt;example&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        %module example
        %{
            #include "cexample.h" 
            #include "CppExample.h"    
        %}
        %include "cexample.h" 
        %include "CppExample.h" 
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;It looks odd to have header files appear twice. The code inside the &lt;code&gt;%{...%}&lt;/code&gt; (with a &amp;#8217;#&amp;#8217; before each &lt;code&gt;include&lt;/code&gt;) are standard C and C&amp;#043;&amp;#043; statements, &lt;em&gt;etc.&lt;/em&gt; that will be inserted verbatim into the generated &amp;#8220;wrapper&amp;#8221; file, &lt;code&gt;example_wrap.cpp&lt;/code&gt;, so that file will compile when it references anything declared in the header files. The second case, with a &amp;#8217;%&amp;#8217; before the &lt;code&gt;include&lt;/code&gt; statements&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;, tells &lt;span class="caps"&gt;SWIG&lt;/span&gt; to make all the declarations in those header files available to the target language. (You can be more selective, if you prefer&amp;#8230;)&lt;/p&gt;


	&lt;p&gt;Following Ruby conventions, the Ruby plugin for &lt;span class="caps"&gt;SWIG&lt;/span&gt; automatically names the module with an upper case first letter (&lt;code&gt;Example&lt;/code&gt;), but you use &lt;code&gt;require 'example'&lt;/code&gt; to include it, as we&amp;#8217;ll see shortly.&lt;/p&gt;


	&lt;h3&gt;Building&lt;/h3&gt;


	&lt;p&gt;See the &lt;code&gt;cpp/Makefile&lt;/code&gt; for the gory details. In a nutshell, you run the &lt;code&gt;swig&lt;/code&gt; command like this.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        swig -c++ -ruby -Wall -o example_wrap.cpp example.i
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Next, you create a dynamically-linked library, as appropriate for your platform, so the Ruby interpreter can load the module dynamically when required. The &lt;code&gt;Makefile&lt;/code&gt; can do this for Linux and &lt;span class="caps"&gt;OS X&lt;/span&gt; platforms. See the &lt;a href="http://www.swig.org/Doc1.3/Ruby.html"&gt;Ruby section&lt;/a&gt; of the &lt;span class="caps"&gt;SWIG&lt;/span&gt; manual for Windows specifics.&lt;/p&gt;


	&lt;p&gt;If you test-drive your code, which tends to drive you towards minimally-coupled &amp;#8220;modules&amp;#8221;, then you can keep your libraries and build times small, which will make the build and test cycle very fast!&lt;/p&gt;


	&lt;h3&gt;&lt;code&gt;spec/cexample_spec.rb&lt;/code&gt; and &lt;code&gt;spec/cppexample_spec.rb&lt;/code&gt;&lt;/h3&gt;


	&lt;p&gt;Finally, here are the RSpec files that exercise the C and C&amp;#043;&amp;#043; code. (Disclaimer: these aren&amp;#8217;t the best spec files I&amp;#8217;ve ever written. For one thing, they don&amp;#8217;t exercise all the &lt;code&gt;CppExample&lt;/code&gt; methods! So sue me&amp;#8230; :)&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
        require File.dirname(__FILE__) + '/spec_helper'
        require 'example'

        describe "Example (C functions)" do
          it "should be a constant on Module" do
            Module.constants.should include('Example')
          end
          it "should have the methods defined in the C header file" do
            Example.methods.should include('returnString')
            Example.methods.should include('returnDouble')
            Example.methods.should include('doNothing')
          end
        end

        describe Example, ".returnString" do
          it "should return the input char * string as a Ruby string unchanged" do
            Example.returnString("bar!").should == "bar!" 
          end  
        end

        describe Example, ".returnDouble" do
          it "should return the input integer as a double" do
            Example.returnDouble(10).should == 10.0
          end
        end

        describe Example, ".doNothing" do
          it "should exist, but do nothing" do
            lambda { Example.doNothing }.should_not raise_error
          end
        end
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;and&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
    require File.dirname(__FILE__) + '/spec_helper'
    require 'example'

    describe Example::CppExample do
      it "should be a constant on module Example" do
        Example.constants.should include('CppExample')
      end
    end

    describe Example::CppExample, ".new" do
      it "should create a new object of type CppExample" do
        example = Example::CppExample.new("example1", 1)
        example.title.should == "example1" 
        example.flag.should  == 1
      end
    end

    describe Example::CppExample, "#title(value)" do
      it "should set the title" do
        example = Example::CppExample.new("example1", 1)
        example.title("title2")
        example.title.should == "title2" 
      end
    end

    describe Example::CppExample, "#flag(value)" do
      it "should set the flag" do
        example = Example::CppExample.new("example1", 1)
        example.flag(2)
        example.flag.should == 2
      end
    end
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;If you love RSpec like I do, this is a very compelling thing to see!&lt;/p&gt;


	&lt;p&gt;And now for the small print:&lt;/p&gt;


	&lt;h2&gt;Current Limitations&lt;/h2&gt;


	&lt;p&gt;As I said, this is just an experiment at this point. Volunteers to make this &lt;em&gt;battle-ready&lt;/em&gt; would be most welcome!&lt;/p&gt;


	&lt;h3&gt;General&lt;/h3&gt;


	&lt;h4&gt;The Example &lt;code&gt;Makefile&lt;/code&gt; File&lt;/h4&gt;


	&lt;p&gt;&lt;strong&gt;It Must Be Hand Edited for Each New or Renamed Source File&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;You&amp;#8217;ve probably already solved this problem for your own make files. Just merge in the example &lt;code&gt;Makefile&lt;/code&gt; to pick up the &lt;span class="caps"&gt;SWIG&lt;/span&gt;- and RSpec-related targets and rules.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;It Only Knows How to Build Shared Libraries for Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; and Linux (and Not Very Well)&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;Some definitions are probably unique to my &lt;span class="caps"&gt;OS X&lt;/span&gt; and Linux machines. Windows is not supported at all. However, this is also easy rectify. Start with the notes in the &lt;code&gt;Makefile&lt;/code&gt; itself.&lt;/p&gt;


	&lt;h4&gt;The &lt;code&gt;module.i&lt;/code&gt; File Must Be Hand Edited for Each File Change&lt;/h4&gt;


	&lt;p&gt;Since the format is simple, a make task could fill a template file with the changed list of source files during the build.&lt;/p&gt;


	&lt;h4&gt;Better Automation&lt;/h4&gt;


	&lt;p&gt;It should be straightforward to provide scripts, &lt;span class="caps"&gt;IDE&lt;/span&gt;/Editor shortcuts, &lt;em&gt;etc&lt;/em&gt;. that automate some of the tasks of adding new methods and classes to your C and C&amp;#043;&amp;#043; code when you introduce them  &lt;i&gt;first&lt;/i&gt; in your &amp;#8220;spec&amp;#8221; files. (The true &lt;span class="caps"&gt;TDD&lt;/span&gt; way, of course.)&lt;/p&gt;


	&lt;h3&gt;Specific Issues for C Code Testing&lt;/h3&gt;


	&lt;p&gt;I don&amp;#8217;t know of any other C-specific issues, so unit testing with Ruby is most viable today for C code. Although I haven&amp;#8217;t experimented extensively, C functions and variables are easily mapped by &lt;span class="caps"&gt;SWIG&lt;/span&gt; to a Ruby module. The &lt;a href="http://www.swig.org/Doc1.3/Ruby.html"&gt;Ruby section&lt;/a&gt; of the &lt;span class="caps"&gt;SWIG&lt;/span&gt; manual discusses this mapping in some detail.&lt;/p&gt;


	&lt;h3&gt;Specific Issues for C&amp;#043;&amp;#043; Code Testing&lt;/h3&gt;


	&lt;p&gt;More work will be required to make this viable. It&amp;#8217;s important to note that &lt;span class="caps"&gt;SWIG&lt;/span&gt; cannot handle all C&amp;#043;&amp;#043; constructs (although there are workarounds for most issues, if you&amp;#8217;re committed to this approach&amp;#8230;). For example, namespaces, nested classes, some template and some method overloading scenarios are not supported. The &lt;a href="http://www.swig.org/Doc1.3"&gt;&lt;span class="caps"&gt;SWIG&lt;/span&gt; manual&lt;/a&gt; has details.&lt;/p&gt;


	&lt;p&gt;Also, during my experiment, &lt;span class="caps"&gt;SWIG&lt;/span&gt; didn&amp;#8217;t seem to map &lt;code&gt;const std::string&amp;#38;&lt;/code&gt; objects in C&amp;#043;&amp;#043; method signatures to Ruby strings, as I would have expected (&lt;code&gt;char*&lt;/code&gt; worked fine).&lt;/p&gt;


	&lt;h2&gt;Is It a Viable Approach?&lt;/h2&gt;


	&lt;p&gt;Once the &lt;strong&gt;General&lt;/strong&gt; issues listed above are handled, I think this approach would work very well for C code. For C&amp;#043;&amp;#043; code, there are more issues that need to be addressed, and programmers who are committed to this strategy will need to tolerate some issues (or just use C&amp;#043;&amp;#043;-language tools for some scenarios).&lt;/p&gt;


	&lt;h2&gt;Conclusions: Making It Development-Team Ready&lt;/h2&gt;


	&lt;p&gt;I&amp;#8217;d like to see this approach pushed to its logical limit. I think it has the potential to really improve the productivity of C and C&amp;#043;&amp;#043; developers and the quality of their test coverage, by leveraging the productivity and power of dynamically-typed languages like Ruby. If you prefer, you could use Tcl, Python, even Java instead.&lt;/p&gt;


	&lt;h3&gt;License&lt;/h3&gt;


	&lt;p&gt;This code is complete open and free to use. Of course, use it at your own risk; I offer it without warranty, &lt;em&gt;etc.&lt;/em&gt;, &lt;em&gt;etc&lt;/em&gt;. When I polish it to the point of making it an &amp;#8220;official&amp;#8221; project, I will probably release under the Apache license.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; I spent a lot of time debugging problems because I had a &amp;#8217;#&amp;#8217; where I should have had a &amp;#8217;%&amp;#8217;! &lt;em&gt;Caveat emptor&lt;/em&gt;!&lt;/p&gt;</description>
      <pubDate>Mon, 04 Feb 2008 22:08:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:cba4dc23-cbce-4173-be6f-14c7847dcfea</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2008/02/04/unit-testing-c-and-c-with-ruby-and-rspec</link>
      <category>Embedded</category>
      <category>Dean's Deprecations</category>
      <category>Dynamic Languages</category>
      <category>Agile Methods</category>
      <category>c</category>
      <category>RSpec</category>
      <category>Ruby</category>
      <category>TDD</category>
      <category>testing</category>
    </item>
    <item>
      <title>TDD for AspectJ Aspects</title>
      <description>&lt;p&gt;There was a query on the &lt;span class="caps"&gt;TDD&lt;/span&gt; mailing list about how to test drive aspects. Here is an edited version of my reply to that list.&lt;/p&gt;


	&lt;p&gt;Just as for regular classes, &lt;span class="caps"&gt;TDD&lt;/span&gt; can drive aspects to a better design.&lt;/p&gt;


	&lt;p&gt;Assume that I&amp;#8217;m testing a logging aspect that logs when certain methods are called. Here&amp;#8217;s the JUnit 4 test:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;package logging;
import static org.junit.Assert.*;
import org.junit.Test;
import app.TestApp;

public class LoggerTest {
    @Test
    public void FakeLoggerShouldBeCalledForAllMethodsOnTestClasses() {
        String message = "hello!";
        new TestApp().doFirst(message);
        assertTrue(FakeLogger.messageReceived().contains(message));
        String message2 = "World!";
        new TestApp().doSecond(message, message2);
        assertTrue(FakeLogger.messageReceived().contains(message));
    }
}
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Already, you might guess that &lt;code&gt;FakeLogger&lt;/code&gt; will be a test-only version of something, in this case, my logging aspect. Similarly, &lt;code&gt;TestApp&lt;/code&gt; is a simple class that I&amp;#8217;m using only for testing. You might choose to use one or more production classes, though.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;package app;
@Watchable
public class TestApp {
    public void doFirst(String message) {}
    public void doSecond(String message1, String message2) {}
}
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;and &lt;code&gt;@Watchable&lt;/code&gt; is a marker annotation that allows me to define pointcuts in my logger aspect without fragile coupling to concrete names, etc. You could also use an interface.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;package app;
public @interface Watchable {}
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;I made up &lt;code&gt;@Watchable&lt;/code&gt; as a way of marking classes where the public methods might be of &amp;#8220;interest&amp;#8221; to particular observers of some kind. It&amp;#8217;s analogous to the &lt;span class="caps"&gt;EJB 3&lt;/span&gt; annotations that mark classes as &amp;#8220;persistable&amp;#8221; without implying too many details of what that might mean.&lt;/p&gt;


	&lt;p&gt;Now, the actual logging is divided into an abstract base aspect and a test-only concrete &lt;a href="&lt;/p"&gt;sub-aspect&lt;/a&gt;&amp;gt;


&lt;pre&gt;&lt;code&gt;package logging;

import org.aspectj.lang.JoinPoint;
import app.Watchable;

abstract public aspect AbstractLogger {
    // Limit the scope to the packages and types you care about.
    public abstract pointcut scope();

    // Define how messages are actually logged.
    public abstract void logMessage(String message);

    // Notice the coupling is to the @Watchable abstraction.
    pointcut watch(Object object):
        scope() &amp;#38;&amp;#38; call(* (@Watchable *).*(..)) &amp;#38;&amp;#38; target(object);

    before(Object watchable): watch(watchable) {
        logMessage(makeLogMessage(thisJoinPoint));
    }

    public static String makeLogMessage(JoinPoint joinPoint) {
        StringBuffer buff = new StringBuffer();
        buff.append(joinPoint.toString()).append(", args = ");
        for (Object arg: joinPoint.getArgs())
            buff.append(arg.toString()).append(", ");
        return buff.toString();
    }
}
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;and&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;package logging;

public aspect FakeLogger extends AbstractLogger {
    // Only match on calls from the unit tests.
    public pointcut scope(): within(logging.*Test);

    public void logMessage(String message) {
        lastMessage = message; 
    }

    static String lastMessage = null;
    public static String messageReceived() {
        return lastMessage;
    }
}
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Pointcut"&gt;Pointcuts&lt;/a&gt; in aspects are like most other dependencies, best avoided ;) ... or at least minimized and based on abstractions, just like associations and inheritance relationships.&lt;/p&gt;


	&lt;p&gt;So, my test &amp;#8220;pressure&amp;#8221; drove the design in terms of where I needed abstraction in the Logger aspect: (i) how a message is actually logged and (ii) what classes get &amp;#8220;advised&amp;#8221; with logging behavior.&lt;/p&gt;


	&lt;p&gt;Just as for &lt;span class="caps"&gt;TDD&lt;/span&gt; of regular classes, the design ends up with minimized dependencies and flexibility (abstraction) where it&amp;#8217;s most useful.&lt;/p&gt;


	&lt;p&gt;I can now implement the real, concrete logger, which will also be a sub-aspect of &lt;code&gt;AbstractLogger&lt;/code&gt;. It will define the &lt;code&gt;scope()&lt;/code&gt; pointcut to be a larger section of the system and it will send the message to the real logging subsystem.&lt;/p&gt;</description>
      <pubDate>Tue, 02 Oct 2007 11:34:24 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:dba855da-6d02-428b-a74b-3f90ff03cdd4</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2007/10/02/tdd-for-aspectj-aspects</link>
      <category>Dean's Deprecations</category>
      <category>Agile Methods</category>
      <category>Design Principles</category>
      <category>TDD</category>
      <category>aspects</category>
      <category>AspectJ</category>
    </item>
    <item>
      <title>Why you have time for TDD (but may not know it yet...)</title>
      <description>&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; Updated 9/30/2007 to improve the graphs and to clarify the content.&lt;/p&gt;


	&lt;p&gt;A common objection to &lt;span class="caps"&gt;TDD&lt;/span&gt; is this; &amp;#8220;We don&amp;#8217;t have time to write so many tests. We don&amp;#8217;t even have enough time to write features!&amp;#8221;&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s why people who say this probably already have enough time in the (real) schedule, they just don&amp;#8217;t know it yet.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s start with an idealized &lt;a href="http://www.controlchaos.com/about/burndown.php"&gt;Scrum-style &amp;#8220;burn-down chart&amp;#8221;&lt;/a&gt; for a fictional project run in a &amp;#8220;traditional&amp;#8221; way (even though traditional projects don&amp;#8217;t use burn-down charts&amp;#8230;).&lt;/p&gt;


&lt;p&gt;
&lt;img src="http://blog.objectmentor.com/files/ideal_timeline2.png" border="0" height="352" width="575" alt="ideal_timeline2.png" align="center" /&gt;
&lt;/p&gt;

	&lt;p&gt;We have time increasing on the x axis and the number of &amp;#8220;features&amp;#8221; &lt;em&gt;remaining to implement&lt;/em&gt; on the y axis (it could also be hours or &amp;#8220;story points&amp;#8221; remaining). During a project, a nice feature of burn-down charts is that you can extend the line to see where it intersects the x axis, which is a rough indicator of when you&amp;#8217;ll actually finish.&lt;/p&gt;


	&lt;p&gt;The optimistic planners for our fictional project plan to give the software to QA near the end of the project. They expect QA to find nothing serious, so the release will occur soon thereafter on date &lt;strong&gt;T0&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;Of course, it never works out that way:&lt;/p&gt;


&lt;p&gt;
&lt;img src="http://blog.objectmentor.com/files/actual_timeline2.png" border="0" height="352" width="575" alt="actual_timeline2.png" align="center" /&gt;
&lt;/p&gt;

	&lt;p&gt;The red line is the actual effort for our fictional project. It&amp;#8217;s quite natural for the planned list of features to change as the team reacts to market changes, &lt;em&gt;etc.&lt;/em&gt;. This is why the line goes up sometimes (in &amp;#8220;good&amp;#8221; projects, too!). Since this is a &amp;#8220;traditional&amp;#8221; project, I&amp;#8217;m assuming that there are no automated tests that actually &lt;em&gt;prove&lt;/em&gt; that a given feature is really done. We&amp;#8217;re effectively running &amp;#8220;open loop&amp;#8221;, without the feedback of tests.&lt;/p&gt;


	&lt;p&gt;Inevitably, the project goes over budget and th planned QA drop comes late. Then things get ugly. Without our automated &lt;strong&gt;unit&lt;/strong&gt; tests, there are lots of little bugs in the code. Without our automated &lt;strong&gt;integration&lt;/strong&gt; tests, there are problems when the subsystems are run together. Without our &lt;strong&gt;acceptance&lt;/strong&gt; tests, the implemented features don&amp;#8217;t quite match the actual requirements for them.&lt;/p&gt;


	&lt;p&gt;Hence, a chaotic, end-of-project &amp;#8220;birthing&amp;#8221; period ensues, where QA reports a list of big and small problems, followed by a frantic effort (usually involving weekends&amp;#8230;) by the developers to address the problems, followed by another QA drop, followed by&amp;#8230;, and so forth.&lt;/p&gt;


	&lt;p&gt;Finally, out of exhaustion and because everyone else is angry at the painful schedule slip, the team declares &amp;#8220;victory&amp;#8221; and ships it, at time &lt;strong&gt;T1&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;We&amp;#8217;ve all lived through projects like this one.&lt;/p&gt;


	&lt;p&gt;Now, if you remember your calculus classes (sorry to bring up painful memories), you will recall that the area under the curve is the total quantity of whatever the curve represents. So, the actual &lt;em&gt;total&lt;/em&gt; feature work required for our project corresponds to the area under the red line, while the planned work corresponds to the area under the black line. So, we really &lt;em&gt;did&lt;/em&gt; have more time than we originally thought.&lt;/p&gt;


	&lt;p&gt;Now consider a Test-Driven Development (TDD) project &lt;a href="#note1"&gt;[1]&lt;/a&gt;:&lt;/p&gt;


&lt;p&gt;
&lt;img src="http://blog.objectmentor.com/files/tdd_timeline2.png" border="0" height="348" width="564" alt="tdd_timeline2.png" align="center" /&gt;
&lt;/p&gt;

	&lt;p&gt;Here, the blue line is similar to the red line, at least early in the project. Now we have frequent &amp;#8220;milestones&amp;#8221; where we &lt;em&gt;verify the state&lt;/em&gt; of the project with the three kinds of automated tests mentioned above. Each milestone is the end of an iteration (usually 1-4 weeks apart). Not shown are the 5-minute &lt;span class="caps"&gt;TDD&lt;/span&gt; cycles and the feedback from the &lt;a href="http://martinfowler.com/articles/continuousIntegration.html"&gt;continuous integration&lt;/a&gt; process that does our builds and runs all our tests after every block of commits to version control (many times a day).&lt;/p&gt;


	&lt;p&gt;The graph suggests that the total amount of effort will be higher than the &lt;em&gt;expected&lt;/em&gt; effort without tests, which may be true &lt;a href="#note2"&gt;[2]&lt;/a&gt;. However, because of the constant feedback during the whole life of the project, we &lt;em&gt;really&lt;/em&gt; know where we actually are at any time. By measuring our progress in this way, we will know early whether or not we can meet the target date with the planned feature set. With early warnings, we can adjust accordingly, either dropping features or moving the target date, with relatively little pain. Whereas, without this feedback, we really don&amp;#8217;t &lt;em&gt;know&lt;/em&gt; what&amp;#8217;s done until something, &lt;em&gt;e.g.,&lt;/em&gt; the QA process, gives us that feedback. Hence, at time &lt;strong&gt;T0&lt;/strong&gt;, just before the big QA drop, the traditional project has little certainty about what features are really completed.&lt;/p&gt;


	&lt;p&gt;So, we&amp;#8217;ll experience less of the traditional end-of-project chaos, because there will be fewer surprises. Without the feedback from automated tests, QA is find lots of problems, causing the chaotic and painful end-of-project experience. Finding and trying to fix major problems late in the game can even kill a project.&lt;/p&gt;


	&lt;p&gt;So, &lt;span class="caps"&gt;TDD&lt;/span&gt; converts that unknown schedule time at the end into known time early in the project. You really &lt;strong&gt;do&lt;/strong&gt; have time for automated tests and your tests will make your projects more predictable and less painful at the end.&lt;/p&gt;


	&lt;p&gt;Note: I appreciate the early comments and questions that helped me clarify this post.&lt;/p&gt;


	&lt;p&gt;&lt;a name="note1"&gt;&lt;/a&gt;
[1] As one commenter remarked, this post doesn&amp;#8217;t actually make the case for &lt;span class="caps"&gt;TDD&lt;/span&gt; itself &lt;em&gt;vs.&lt;/em&gt; alternative &amp;#8220;test-heavy&amp;#8221; strategies, but I think it&amp;#8217;s pretty clear that &lt;span class="caps"&gt;TDD&lt;/span&gt; is the best of the known test-heavy strategies, as argued elsewhere.&lt;/p&gt;


	&lt;p&gt;&lt;a name="note2"&gt;&lt;/a&gt;
[2] There is some evidence that &lt;span class="caps"&gt;TDD&lt;/span&gt; and pair programming lead to &lt;em&gt;smaller&lt;/em&gt; applications, because they help avoid unnecessary features. Also, they provide constant feedback to the team, including the stake holders, on what the feature set should really be and which features are most important to complete first.&lt;/p&gt;</description>
      <pubDate>Sun, 30 Sep 2007 20:01:02 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:98c607d8-ce1b-4e35-aabd-8717de80bde6</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2007/09/30/why-you-have-time-for-tdd-but-may-not-know-it-yet</link>
      <category>Dean's Deprecations</category>
      <category>Agile Methods</category>
      <category>projects</category>
      <category>schedules</category>
      <category>TDD</category>
    </item>
    <item>
      <title>Not A Task, But An Approach</title>
      <description>&lt;p&gt;Transitions are tough. It seems that lately I&amp;#8217;ve been getting a lot of contact from frustrated people who don&amp;#8217;t really have a good handle on the &amp;#8220;drive&amp;#8221; part of Test Driven Development.  A question heard frequently is: &amp;#8220;I&amp;#8217;ve almost completed the coding, can you help me write the &lt;span class="caps"&gt;TDD&lt;/span&gt;?&amp;#8221;&lt;/p&gt;


	&lt;p&gt;It seems like Test Driven Development is taken backward, that the &lt;em&gt;developers&lt;/em&gt; are &lt;em&gt;driven&lt;/em&gt; to write &lt;em&gt;tests&lt;/em&gt;.  The practitioner winces, realizing that he again faces The Great Misunderstanding of &lt;span class="caps"&gt;TDD&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt; stands for Test-Driven Development, which is not as clear as &lt;span class="caps"&gt;TFD&lt;/span&gt; (Test-First Development). If the consultant would strive to always say the word &amp;#8220;first&amp;#8221; in association with testing, most people would more surely grasp the idea.  In fact, I&amp;#8217;ve begun an experiment in which I will not say the word &amp;#8220;test&amp;#8221; without the word &amp;#8220;first&amp;#8221; in close approximation. I&amp;#8217;ll let you know how that works out for me.&lt;/p&gt;


	&lt;p&gt;If the tests are providing nothing more than reassurance on the tail end of a coding phase, then the tests aren&amp;#8217;t driving the development.  They are like &lt;em&gt;riders&lt;/em&gt; instead of &lt;em&gt;drivers&lt;/em&gt;.  Test-Ridden Development (TRD)[1] would be a better term for such a plan. Even though it is better to have those tail-end tests than to have no automated testing, it misses the point and could not be reasonably be called &lt;span class="caps"&gt;TDD&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;An old mantra for &lt;span class="caps"&gt;TDD&lt;/span&gt; and &lt;span class="caps"&gt;BDD&lt;/span&gt; is &amp;#8220;it&amp;#8217;s not about testing&amp;#8221;. The term &lt;span class="caps"&gt;BDD&lt;/span&gt; was invented largely to get the idea of &amp;#8220;testing&amp;#8221; out of the way.  People tend to associate &amp;#8220;test&amp;#8221; as a release-preparation activity rather than an active approach to programming. &lt;span class="caps"&gt;BDD&lt;/span&gt; alleviates some of that cognitive dissonance.&lt;/p&gt;


	&lt;p&gt;In &lt;span class="caps"&gt;TDD&lt;/span&gt;, tests come first. Each unit test is written as it is needed by the programmer.  Tests are just-in-time and are active in shaping the code. Acceptance Tests likewise tend to precede programming by some short span of time.  [2]&lt;/p&gt;


Through months of repetition I have developed the mantra:
&lt;blockquote&gt;
&lt;span class="caps"&gt;TDD&lt;/span&gt; isn&amp;#8217;t a task. It is not something you do.  It is an approach.  It is how you write your programs.
&lt;/blockquote&gt;

	&lt;p&gt;I wonder if we shouldn&amp;#8217;t resurrect the term Test-First Programming or Test-First Development for simple evocative power. Admittedly there are some who would see that as a phase ordering, but maybe enough people would get the right idea.&lt;/p&gt;


	&lt;p&gt;Brett Schuchert(with some trivial aid from your humble blogger) has worked up an acronym to help socialize the basic concepts which are somehow being lost in translation to the corporate workplace.&lt;/p&gt;


	&lt;p&gt;The teaser:
    Fast, Isolated, Repeatable, Self-validating, and Timely.&lt;/p&gt;


	&lt;p&gt;As a reader of this blog, you are probably very familiar with all of the terminology and concepts behind &lt;span class="caps"&gt;TDD&lt;/span&gt;. I beg of you, socialize the idea that testing comes first and drives the shape of the code.  If we can just get this one simple idea spread into programming dens across our small spheres of influence, then we will have won a very great victory over Test-Ridden Development.&lt;/p&gt;


	&lt;p&gt;&amp;#8220;And there was much rejoicing.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;&lt;small&gt;
1 Jeff Langr will refer to this &lt;span class="caps"&gt;TRD&lt;/span&gt; concept as &amp;#8220;Test-After-Development&amp;#8221;, which he follows with a chuckle and a twinkle, &amp;#8220;which is a &lt;span class="caps"&gt;TAD&lt;/span&gt; too late.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;2 Of course, one still needs QC testing as well, however &lt;span class="caps"&gt;TDD&lt;/span&gt; is about driving development, not testing its quality post-facto.
&lt;/small&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 02 Aug 2007 22:14:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:bd848598-96fa-4e15-84e8-ccba83ab4325</guid>
      <author>Tim Ottinger</author>
      <link>http://blog.objectmentor.com/articles/2007/08/02/not-a-task-but-an-approach</link>
      <category>Tim's Tepid Torrent</category>
      <category>FIRST</category>
      <category>testing</category>
      <category>mentoring</category>
      <category>TDD</category>
      <category>TRD</category>
      <category>TAD</category>
      <category>Fast</category>
      <category>Isolated</category>
      <category>Repeatable</category>
      <category>Self</category>
      <category>validating</category>
      <category>Timely</category>
    </item>
    <item>
      <title>Which came First?</title>
      <description>I like mnemonics. Many years ago, a colleague of mine, James, gave me a way to remember something. First I&amp;#8217;ll give you the letters:
	&lt;ul&gt;
	&lt;li&gt;   &lt;span class="caps"&gt;CCCCDPIPE&lt;/span&gt;&lt;/li&gt;
	&lt;/ul&gt;


These letters are a way to remember Craig Larman&amp;#8217;s &lt;span class="caps"&gt;GRASP&lt;/span&gt; patterns (version 1). This and knowing that in the second version of the &lt;span class="caps"&gt;GRASP&lt;/span&gt; patterns Craig replaced the D for P (D &#226;&#8364;&#8220; Don&amp;#8217;t talk to strangers &#226;&#8364;&#8220; the Law of Demeter, P &#226;&#8364;&#8220; Protected Variation). By the way, here are all of them:
	&lt;ul&gt;
	&lt;li&gt;Coupling (low)&lt;/li&gt;
		&lt;li&gt;Cohesion (high)&lt;/li&gt;
		&lt;li&gt;Creator&lt;/li&gt;
		&lt;li&gt;Controller&lt;/li&gt;
		&lt;li&gt;Don&amp;#8217;t talk to strangers (mentioned above and replaced with Protected Variation)&lt;/li&gt;
		&lt;li&gt;Polymorphism&lt;/li&gt;
		&lt;li&gt;Indirection&lt;/li&gt;
		&lt;li&gt;Pure Fabrication&lt;/li&gt;
		&lt;li&gt;Expert&lt;/li&gt;
	&lt;/ul&gt;


How do I remember the letters? Well walk through this bad pun with me:
	&lt;ul&gt;
	&lt;li&gt;&lt;span class="caps"&gt;CCCC&lt;/span&gt; (4 c&amp;#8217;s, foresees)&lt;/li&gt;
		&lt;li&gt;D (the)&lt;/li&gt;
		&lt;li&gt;&lt;span class="caps"&gt;PIPE&lt;/span&gt; (pipe)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;So who foresees the pipe? The Psychic Plumber.&lt;/p&gt;


	&lt;p&gt;The Psychic Plumber??? I know, it&amp;#8217;s awful. However, I heard it once in something like 1999 and I&amp;#8217;ve never forgotten it.&lt;/p&gt;


	&lt;p&gt;That leads me to some other oldies but goodies: &lt;span class="caps"&gt;SOLID&lt;/span&gt;, INVEST, &lt;span class="caps"&gt;SMART&lt;/span&gt; and a relative new-comer: &lt;span class="caps"&gt;FIRST&lt;/span&gt;. While these are actually acronyms (not just abbreviations but real, dictionary-defined acronyms), they are also mnemonics.&lt;/p&gt;


	&lt;p&gt;You might be thinking otherwise. Typically what people call acronyms are actually just abbreviations. And in any case, they tend to obfuscate rather than elucidate. However, if you&amp;#8217;ll lower your guard for just a few more pages, you might find some of these helpful.&lt;/p&gt;


Your software should be &lt;span class="caps"&gt;SOLID&lt;/span&gt;:
	&lt;ul&gt;
	&lt;li&gt;Single Responsibility&lt;/li&gt;
		&lt;li&gt;Open/Closed Principle&lt;/li&gt;
		&lt;li&gt;Liskov Substitution Principle&lt;/li&gt;
		&lt;li&gt;Interface Segregation&lt;/li&gt;
		&lt;li&gt;Dependency Inversion Principle (not to be confused with Dependency Inversion)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;I think we should change the spelling: &lt;span class="caps"&gt;SOLIDD&lt;/span&gt; and tack on &#226;&#8364;&#339;Demeter &#226;&#8364;&#8220; the Law Of. But that&amp;#8217;s just me. Of course if we do this, then it is no longer technically an acronym. That&amp;#8217;s OK, because my preference is for mnemonics, not acronyms.&lt;/p&gt;


When you&amp;#8217;re working on your user stories, make sure to &lt;span class="caps"&gt;INVEST&lt;/span&gt; in them:
	&lt;ul&gt;
	&lt;li&gt;Independent&lt;/li&gt;
		&lt;li&gt;Negotiable&lt;/li&gt;
		&lt;li&gt;Valuable&lt;/li&gt;
		&lt;li&gt;Estimable&lt;/li&gt;
		&lt;li&gt;Small        &lt;/li&gt;
		&lt;li&gt;Testable&lt;/li&gt;
	&lt;/ul&gt;


And if you&amp;#8217;re working on tasks, make sure to keep them &lt;span class="caps"&gt;SMART&lt;/span&gt;:
	&lt;ul&gt;
	&lt;li&gt;Specific&lt;/li&gt;
		&lt;li&gt;Measurable&lt;/li&gt;
		&lt;li&gt;Achievable&lt;/li&gt;
		&lt;li&gt;Relevant&lt;/li&gt;
		&lt;li&gt;Time-boxed&lt;/li&gt;
	&lt;/ul&gt;


What what is &lt;span class="caps"&gt;FIRST&lt;/span&gt;? Well have you ever heard Test Driven Development (TDD)? Some people call it by an older name, Test-First Programming (TFP). I don&amp;#8217;t think of these as the same thing but that&amp;#8217;s neither here nor there. What if the F in &lt;span class="caps"&gt;TFP&lt;/span&gt; really stands for &lt;span class="caps"&gt;FIRST&lt;/span&gt; (notice how I sneaked in the capitals)? If so, then here&amp;#8217;s one possible interpretation:
	&lt;ul&gt;
	&lt;li&gt;Fast &amp;#8211; tests should run fast.  We should be able to run all of the tests in seconds or minutes. Running the tests should never feel like a burden. If a developer ever hesitates to execute tests because of time, then the tests tests take too long.&lt;/li&gt;
		&lt;li&gt;Isolated &amp;#8211; A test is a sealed environment.  Tests should not depend on the results of  other tests, nor should they depend on external resources such as databases.&lt;/li&gt;
		&lt;li&gt;Repeatable &#226;&#8364;&#8220; when a test fails, it should fail because the production code is broken, not  because some external dependency failed (e.g. database unavailable, network  problems, etc.)&lt;/li&gt;
		&lt;li&gt;Self-Validating &amp;#8211; Manual interpretation of results does not scale. A test should * verify that it passed or failed. Going one step further, a test should report nothing but success or failure.&lt;/li&gt;
		&lt;li&gt;Timely &amp;#8211; tests should be written concurrently (and preferably before) with production code.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;So where does this acronym come from? A while back, a colleague of mine, Tim Ottinger, and I were working on some course notes. I had a list of four out of five of these ideas. We were working on the characteristics of a good unit test. At one point, Tim said to me &#226;&#8364;&#339;Add a T.&#226;&#8364;&#157;&lt;/p&gt;


	&lt;p&gt;I can be pretty dense fairly often. I didn&amp;#8217;t even understand what he was telling me to do. He had to repeat himself a few times. I understood the words, but not the meaning (luckily that doesn&amp;#8217;t happen to other people or we&amp;#8217;d have problems writing software). Anyway, I finally typed a &#226;&#8364;&#339;T&#226;&#8364;&#157;. And then I asked him &#226;&#8364;&#339;Why?&#226;&#8364;&#157; I didn&amp;#8217;t see the word. Apparently you don&amp;#8217;t want me on your unscramble team either.&lt;/p&gt;


	&lt;p&gt;Well eventually he led me to see the word &lt;span class="caps"&gt;FIRST&lt;/span&gt; and it just seemed to fit (not sure if that pun was intended).&lt;/p&gt;


	&lt;p&gt;Of course, you add all of these together and what do you get? The best I can come up with is: &lt;span class="caps"&gt;SFP&lt;/span&gt;-IS. I was hoping I could come up with a Roman numeral or something because then I could say developers should always wear &lt;span class="caps"&gt;SPF IS&lt;/span&gt; &amp;#8211; which is true because we say out of the sun and burn easily. Unfortunately that did not work. If you look at your phone, you can convert this to the number: 73747&lt;/p&gt;


	&lt;p&gt;If there are any numerologists out there, maybe you can make some sense of it.&lt;/p&gt;


	&lt;p&gt;In any case, consider remembering some of these mnemonics. If you actually do more than remember them and start practicing them, I believe you&amp;#8217;ll become a better developer.&lt;/p&gt;</description>
      <pubDate>Thu, 02 Aug 2007 16:43:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:24504899-46fc-4769-9d4d-4796aa318cb2</guid>
      <author>Brett Schuchert</author>
      <link>http://blog.objectmentor.com/articles/2007/08/02/which-came-first</link>
      <category>Schuchert's Scattered Synapses </category>
      <category>TDD</category>
      <category>TFP</category>
      <category>FIRST</category>
      <category>Unit</category>
      <category>Tests</category>
    </item>
    <item>
      <title>Observations on TDD in C++ (long)</title>
      <description>&lt;p&gt;I spent all of June mentoring teams on &lt;span class="caps"&gt;TDD&lt;/span&gt; in C++ with some Java. While C++ was my language of choice through most of the 90&amp;#8217;s, I think far too many teams are using it today when there are better options for their particular needs.&lt;/p&gt;


	&lt;p&gt;During the month, I took notes on all the ways that C++ development is less productive than development in languages like Java, particular if you try to practice &lt;span class="caps"&gt;TDD&lt;/span&gt;. I&amp;#8217;m not trying to start a language flame war. There are times when C++ is the appropriate tool, as we&amp;#8217;ll see.&lt;/p&gt;


	&lt;p&gt;Most of the points below have been discussed before, but it is useful to list them in one place and to highlight a few particular observations.&lt;/p&gt;


	&lt;p&gt;Based on my observations last month, as well as previously experience, I&amp;#8217;ve come to the conclusion that &lt;span class="caps"&gt;TDD&lt;/span&gt; in C++ is about an &lt;em&gt;order of magnitude&lt;/em&gt; slower than &lt;span class="caps"&gt;TDD&lt;/span&gt; in Java. Mostly, this is due to poor or non-existent tool support for automated refactorings, no error detection as you type, and the requirement to compile and link an executable test.&lt;/p&gt;


	&lt;p&gt;So, here is my list of impediments that I encountered last month. I&amp;#8217;ll mostly use Java as the comparison language, but the arguments are more or less the same for C# and the popular dynamic languages, like Ruby, Python, and Smalltalk. Note that the dynamic languages tend to have less complete tool support, but they make up for it in other ways (off-topic for this blog).&lt;/p&gt;


	&lt;h3&gt;Getting Started&lt;/h3&gt;


	&lt;p&gt;There is more setup effort involved in configuring your build environment to use your chosen unit testing framework (&lt;em&gt;e.g.&lt;/em&gt;, CppUnit) and to create small executables, one each for a single or a few tests. Creating many small tests, rather than one big test (&lt;em&gt;e.g.&lt;/em&gt;, a variant of the actual application). This is important to minimize the &lt;span class="caps"&gt;TDD&lt;/span&gt; cycle.&lt;/p&gt;


	&lt;p&gt;Fortunately, this setup is a one-time &amp;#8220;charge&amp;#8221;. The harder part, if you have legacy code, is refactoring it to break hard dependencies so you can write unit tests. This is true for legacy code in any language, of course.&lt;/p&gt;


	&lt;h3&gt;Complex Syntax&lt;/h3&gt;


	&lt;p&gt;C++ has a very complex syntax. This makes it hard to parse, limiting the capabilities of automated tools and slowing build times (more below).&lt;/p&gt;


	&lt;p&gt;The syntax also makes it harder to program in the language and not just for novices. Even for experts, the &lt;em&gt;visual noise&lt;/em&gt; of pointer and reference syntax obscures the story the code is trying to tell. That is, C++ code is inherently less &lt;em&gt;clean&lt;/em&gt; than code in most other languages in widespread use.&lt;/p&gt;


	&lt;p&gt;Also, the need for the developer to remember whether each variable is a pointer, a reference, or a &amp;#8220;value&amp;#8221;, and how to manage its life-cycle, requires mental effort that could be applied to the logic of the code instead.&lt;/p&gt;


	&lt;h3&gt;Obsolete Tool Support&lt;/h3&gt;


	&lt;p&gt;No editor or &lt;span class="caps"&gt;IDE&lt;/span&gt; supports non-trivial, automated refactorings. (Some do simple refactorings like &amp;#8220;rename&amp;#8221;.) This means you have to resort to tedious, slow, and error-prone manual refactorings. &lt;strong&gt;Extract Method&lt;/strong&gt; is made worse by the fact that you usually have to edit two files, an implementation and a header file.&lt;/p&gt;


	&lt;p&gt;There are no widely-used tools that provide on-the-fly parsing and error indications. This alone increases the time between typing an error and learning about it by an order of magnitude. Since a build is usually required, you tend to type a lot between builds, thereby learning about many errors at once. Working through them takes time. (There may be some commercial tools with limited support for on-the-fly parsing, but they are not widely used.)&lt;/p&gt;


	&lt;p&gt;Similarly, none of the common development tools support incremental loading of object code that could be used for faster unit testing and hence a faster &lt;span class="caps"&gt;TDD&lt;/span&gt; cycle. Most teams just build executables. Even when they structure the build process to generate small, focused executables for unit tests, the &lt;span class="caps"&gt;TDD&lt;/span&gt; cycle times remain much longer than for Java.&lt;/p&gt;


	&lt;p&gt;Finally, while there is at least one mocking framework available for C++, it is much harder to use than comparable frameworks in newer languages.&lt;/p&gt;


	&lt;h3&gt;Manual Memory Management&lt;/h3&gt;


	&lt;p&gt;We all know that manual memory management leads to time spent finding and fixing memory errors and leaks. Avoiding these problems in the first place also consumes a lot of thought and design effort. In Java, you just spend far less time thinking about &amp;#8220;who owns this object and is therefore responsible for managing its life-cycle&amp;#8221;.&lt;/p&gt;


	&lt;h4&gt;Dependency Management&lt;/h4&gt;


	&lt;p&gt;Intelligent handling of include directives is entirely up to the developer. We have all used the following &amp;#8220;guard&amp;#8221; idiom:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;    #ifndef MY_CLASS_H
    #define MY_CLASS_H
    ...
    #endif&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Unfortunately, this isn&amp;#8217;t good enough. The file will still get opened and read in its entirety every time it is included. You could also put the guard directives around the include statement:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;    #ifndef MY_CLASS_H
    #include &amp;quot;myclass.h&amp;quot;
    #endif&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This is tedious and few people do it, but it does avoid the wasted file I/O.&lt;/p&gt;


	&lt;p&gt;Finally, too few people simply declare a required class with no body:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;    class MyClass;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This is sufficient when one header references another class as a pointer or reference. In our experience with clients, we have often seen build times improve significantly when teams cleaned up their header file usage and dependencies, in general. Still, why is all this necessary in the 21st century?&lt;/p&gt;


	&lt;p&gt;This problem is made worse by the unfortunate inclusion of private and protected declarations in the same header file included by clients of the class. This creates &lt;em&gt;phantom dependencies&lt;/em&gt; from the clients to class details that they can&amp;#8217;t access directly.&lt;/p&gt;


	&lt;h4&gt;Other Debugging Issues&lt;/h4&gt;


	&lt;p&gt;Limited or non-existent context information when an exception is thrown makes the origin of the exception harder to find. To fill the gap, you tend to spend more time &lt;em&gt;adding&lt;/em&gt; this information manually through logging statements in catch blocks, &lt;em&gt;etc&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;The &lt;tt&gt;std::exception&lt;/tt&gt; class doesn&amp;#8217;t appear to have a &lt;tt&gt;std::string&lt;/tt&gt; or &lt;tt&gt;const char&amp;#42;&lt;/tt&gt; argument in a constructor for a message. You could just throw a string, but that precludes using an exception class with a meaningful name.&lt;/p&gt;


	&lt;p&gt;Compiler error messages are hard to read and often misleading. In part this is due to the complexity of the syntax and the parsing problem mentioned previously. Errors involving template usage are particular hard to debug.&lt;/p&gt;


	&lt;h4&gt;Reflection and Metaprogramming&lt;/h4&gt;


	&lt;p&gt;Many of the productivity gains from using dynamic languages and (to a lesser extent) Java and C# are due to their reflection and metaprogramming facilities. C++ relies more on &lt;em&gt;template metaprogramming&lt;/em&gt;, rather than APIs or other built-in language features that are easier to use and more full-featured. Preprocessor hacks are also used frequently. Better reflection and metaprogramming support would permit more robust &lt;em&gt;proxy&lt;/em&gt; or &lt;em&gt;aspect&lt;/em&gt; solutions to be used. (However, to be fair, sometimes a preprocessor hack has the virtue of being &amp;#8220;the simplest thing that could possibly work.&amp;#8221;)&lt;/p&gt;


	&lt;h4&gt;Library Issues&lt;/h4&gt;


	&lt;p&gt;Speaking of &lt;tt&gt;std::string&lt;/tt&gt; and &lt;tt&gt;char&amp;#42;&lt;/tt&gt;, it is hard to avoid writing two versions of methods, one which takes &lt;tt&gt;const std::string&amp;amp;&lt;/tt&gt; arguments and one which takes &lt;tt&gt;const char&amp;#42;&lt;/tt&gt; arguments. It doesn&amp;#8217;t matter that one method can usually delegate to the other one; this is wasted effort.&lt;/p&gt;


	&lt;h3&gt;Discussion&lt;/h3&gt;


	&lt;p&gt;So, C++ makes it hard for me to work the way that I want to work today, which is test-driven, creating clean code that works. That&amp;#8217;s why I rarely choose it for a project.&lt;/p&gt;


	&lt;p&gt;However, to be fair, there are legitimate reasons for almost all of the perceived &amp;#8220;deficiencies&amp;#8221; listed above. C++ emphasizes performance and backwards-compatibility with C over all other considerations. However, they come at the expense of other interests, like effective &lt;span class="caps"&gt;TDD&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;It &lt;em&gt;is&lt;/em&gt; a &lt;strong&gt;good&lt;/strong&gt; thing that we have languages that were designed with performance as the top design goal, because there are circumstances where performance is the number one requirement. However, most teams that use C++ as their primary language are making an optimal choice for, say, 10% of their code, but which is suboptimal the other 90%. Your numbers will vary; I picked 10% &lt;em&gt;vs.&lt;/em&gt; 90% based on the fact that performance bottlenecks are usually localized and they should be found by actual measurements, not guesses!&lt;/p&gt;


	&lt;h4&gt;Workarounds&lt;/h4&gt;


	&lt;p&gt;If it&amp;#8217;s true that &lt;span class="caps"&gt;TDD&lt;/span&gt; is an order of magnitude slower for C++ then what do we do? No doubt really good C++ developers have optimized their processes as best as they can, but in the end, you will just have to live with longer &lt;span class="caps"&gt;TDD&lt;/span&gt; cycles. Instead of &lt;em&gt;write just enough test to fail, make it pass, refactor&lt;/em&gt;, it will be more like &lt;em&gt;write a complete test, write the implementation, build it, fix the compilation errors, run it, fix the logic errors to make the test pass, and then refactor&lt;/em&gt;.&lt;/p&gt;


	&lt;h4&gt;A Real Resolution?&lt;/h4&gt;


	&lt;p&gt;You could consider switching to the &lt;a href="http://www.digitalmars.com/d/"&gt;D language&lt;/a&gt;, which is link compatible with C and appears to avoid many of the problems described above.&lt;/p&gt;


	&lt;p&gt;There is another way out of the dilemma of needing optimal performance some of the time and optimal productivity the rest of the time; use more than one language. I&amp;#8217;ll discuss this idea in my next blog.&lt;/p&gt;</description>
      <pubDate>Tue, 03 Jul 2007 23:15:09 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:399b620b-c563-4b96-9556-17e24c8f8f74</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2007/07/03/observations-on-tdd-in-c-long</link>
      <category>Dean's Deprecations</category>
      <category>c</category>
      <category>TDD</category>
      <category>D</category>
      <trackback:ping>http://blog.objectmentor.com/articles/trackback/8785</trackback:ping>
    </item>
    <item>
      <title>100% Code Coverage?</title>
      <description>&lt;p&gt;Should you strive for 100% code coverage from your unit tests? It&amp;#8217;s probably not mandatory and if your goal is 100% coverage, you&amp;#8217;ll focus on that goal and not focus on writing the best tests for the &lt;i&gt;behavior&lt;/i&gt; of your code.&lt;/p&gt;


	&lt;p&gt;That said, here are some thoughts on why I still like to get close to 100%.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;I&amp;#8217;m anal retentive. I don&amp;#8217;t like those little red bits in my coverage report. (Okay, that&amp;#8217;s not a good reason&amp;#8230;)&lt;/li&gt;
		&lt;li&gt;Every time I run the coverage report, I have to inspect all the uninteresting cases to find the interesting cases I should cover.&lt;/li&gt;
		&lt;li&gt;The tests are the specification and documentation of the code, so if something nontrivial but unexpected happens, there should still be a test to &amp;#8220;document&amp;#8221; the behavior, even if the test is hard to write.&lt;/li&gt;
		&lt;li&gt;Maybe those places without coverage are telling me to fix the design.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;I was thinking about this last point the other day when considering a bit of Java code that does a downcast (assume that&amp;#8217;s a good idea, for the sake of argument&amp;#8230;), wrapped in a try/catch block for the potential &lt;code&gt;ClassCastException&lt;/code&gt;:&lt;/p&gt;


&lt;pre&gt;
public void handleEvent (Event event) throws ApplicationException {
  try {
    SpecialEvent specialEvent = (SpecialEvent) event;
    doSomethingSpecial (specialEvent);
  } catch (ClassCastException cce) { 
    throw new ApplicationException(cce);
  }
}
&lt;/pre&gt;

	&lt;p&gt;To get 100% coverage, you would have to write a test that inputs an object of a different subtype of &lt;code&gt;Event&lt;/code&gt; to trigger coverage of the catch block. As we all know, these sorts of error-handling code blocks are typically the hardest to cover and ones we&amp;#8217;re most likely to ignore. (When was the last time you saw a &lt;code&gt;ClassCastException&lt;/code&gt; anyway?)&lt;/p&gt;


	&lt;p&gt;So my thought was this, we want 100% of the production code to be developed with &lt;span class="caps"&gt;TDD&lt;/span&gt;, so what if we made 100% coverage a similar goal? How would that change our designs? We might decide that since we have to write a test to cover this error-handling scenario, maybe we should rethink the scenario itself. Is it necessary? Could we eliminate the catch block with a better overall design, in this case, making sure that we test all &lt;i&gt;callers&lt;/i&gt; and ensure that they obey the method&amp;#8217;s &amp;#8216;contract&amp;#8217;? Should we just let the &lt;code&gt;ClassCastException&lt;/code&gt; fly out of the function and let a higher-level catch block handle it? After all, catching and rethrowing a different exception is slightly smelly and the code would be cleaner without the try/catch block. (For completeness, a good use of exception wrapping is to avoid namespace pollution. We might not want application layer A to know anything about layer C&amp;#8217;s exception types, so we wrap a C exception in an A exception, which gets passed through layer B&amp;#8230;)&lt;/p&gt;


	&lt;p&gt;100% coverage is often impossible or impractical, because of language or tool oddities. Still, if you give in early, you&amp;#8217;re overlooking some potential benefits.&lt;/p&gt;</description>
      <pubDate>Wed, 16 May 2007 22:50:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1042dbcd-42aa-4dd1-a2de-3c371b910ba7</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2007/05/16/100-code-coverage</link>
      <category>Dean's Deprecations</category>
      <category>TDD</category>
      <category>code</category>
      <category>coverage</category>
      <trackback:ping>http://blog.objectmentor.com/articles/trackback/7523</trackback:ping>
    </item>
  </channel>
</rss>
