<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Weiqi Gao&#039;s Observations - tests tag</title>
  <link>http://www.weiqigao.com/blog/tags/tests/</link>
  <description>Sharing My Experience...</description>
  <language>en</language>
  <copyright>Weiqi Gao</copyright>
  <lastBuildDate>Fri, 11 May 2012 12:48:36 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  <image>
    <url>http://pebble.sourceforge.net/common/images/powered-by-pebble.gif</url>
    <title>Weiqi Gao&#039;s Observations</title>
    <link>http://www.weiqigao.com/blog/</link>
  </image>
  
  
  <item>
    <title>What Test Driven Won&#039;t Get Me</title>
    <link>http://www.weiqigao.com/blog/2008/04/29/what_test_driven_wont_get_me.html</link>
    
      
        <description>
          &lt;p&gt;Thanks to &lt;a href= &#034;http://www.ociweb.com/javasig/knowledgebase/Oct2000/index.html&#034; &gt;Eric&lt;/a&gt; and &lt;a href= &#034;http://www.onjava.com/pub/a/onjava/2003/04/02/javaxpckbk.html&#034; &gt;Brian&lt;/a&gt; and other &lt;a href= &#034;http://www.ociweb.com/javasig/knowledgebase/2005-10/index.html&#034; &gt;champions&lt;/a&gt; of &lt;a href= &#034;http://www.ociweb.com/javasig/knowledgebase/2008-04/index.html&#034; &gt;test&lt;/a&gt; &lt;a href= &#034;http://www.ociweb.com/javasig/knowledgebase/2005-03/index.html&#034; &gt;first&lt;/a&gt; development, I&#039;ve been profitably writing unit tests and functional tests in &lt;a href= &#034;http://www.weiqigao.com/blog/2005/03/08/we_found_the_bug.html&#034; &gt;various&lt;/a&gt; &lt;a href= &#034;http://www.weiqigao.com/blog/2005/09/20/refactoring_is_garbage_collection_of_the_source.html&#034; &gt;projects&lt;/a&gt; for more than seven years.&lt;/p&gt;

&lt;p&gt;Nowadays I wouldn&#039;t dare delivering anything without having thoroughly tested it.  For me, the tests serves three purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To ensure that the functionalities are implemented correctly&lt;/li&gt;
&lt;li&gt;To discover corner cases that you just couldn&#039;t think of during on-paper design&lt;/li&gt;
&lt;li&gt;To provide a safety net that is needed to confidently refactor the code base to improve design&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, my own experience with the concept of &lt;span style=&#034;color:red&#034;&gt;test driven design&lt;/span&gt; has been mixed.  And here are some of the limitations of the approach, as I see it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your test driven design won&#039;t be that much better than your non-test driven design.  If you know nothing about designing a compiler, no amount of testing will make you come up with a design for a compiler&lt;/li&gt;
&lt;li&gt;Your tests will drive you to designs that are more complicated than necessary, with an abundance of entities and interactions.  You will be doing a lot of &#034;create class&#034;, &#034;create method&#034;, &#034;create field&#034; from the IDEs refactor menu, but rarely do &#034;consolidate classes&#034; or &#034;consolidate methods&#034; because no such refactoring exists&lt;/li&gt;
&lt;li&gt;Your test driven design may drive you towards a design that&#039;s less amendable for future changes.  Without forethought, you may be too focused on delivering functionality that satisfy &lt;span style=&#034;color:red&#034;&gt;only&lt;/span&gt; the current requirements, thinking &#034;I can always refactor later to accommodate future requirements&#034;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, if you don&#039;t know how to design, no amount of testing will make you a good designer.&lt;/p&gt;

&lt;hr size=&#034;1&#034; width=&#034;60%&#034; align=&#034;center&#034; noshade=&#034;noshade&#034;&gt;

&lt;p&gt;In other news, &lt;a href= &#034;http://www.informit.com/articles/article.aspx?p=1193856&#034; &gt;Donald Knuth professes&lt;/a&gt; that &#034;With the caveat that there’s no reason anybody should care about the opinions of a computer scientist/mathematician like me regarding software development, let me just say that almost everything I’ve ever heard associated with the term &#034;extreme programming&#034; sounds like exactly the wrong way to go...with one exception. The exception is the idea of working in teams and reading each other’s code. That idea is crucial, and it might even mask out all the terrible aspects of extreme programming that alarm me.&#034;&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2008/04/29/what_test_driven_wont_get_me.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2008/04/29/what_test_driven_wont_get_me.html</guid>
    <pubDate>Tue, 29 Apr 2008 16:27:54 GMT</pubDate>
  </item>
  
  <item>
    <title>Friday Java Challenge: Write A Regular Expression Parser</title>
    <link>http://www.weiqigao.com/blog/2007/08/17/friday_java_challenge_write_a_regular_expression_parser.html</link>
    
      
        <description>
          &lt;p&gt;Instead of a Friday Java Quiz, I&#039;ll pose a challenge.  And it is not a challenge to your Java skills, but a challenge to the Test-First Design doctrine, which holds that a test-first approach can result in a better or simpler design.&lt;/p&gt;

&lt;p&gt;I first witnessed this principle at work at the first No Fluff Just Stuff conference in St. Louis several years ago, where I sat in on Uncle Bob&#039;s session on test-first design and followed his &#034;score a bowling game&#034; demonstration.&lt;/p&gt;

&lt;p&gt;I have been following a test-driven approach ever since, and I have benefited enormously from this approach: this is true especially in the responsibility allocation among cooperating classes, untangling tightly coupling, and API designs.&lt;/p&gt;

&lt;p&gt;However, I have always felt that certain systems can only be designed with enough knowledge about the domain that might not be gained through the mere writing of tests.  This is particularly true in areas where non-trivial theories are involved in the solution of a problem.  My usual example is &#034;You can&#039;t write Math.sin() with a test-first approach.&#034;&lt;/p&gt;

&lt;p&gt;It seems to me that the test-first design is applicable for trivial problems, but not for complicated problems where the naive solution is the wrong solution.&lt;/p&gt;

&lt;p&gt;With that in mind, here&#039;s today&#039;s Java challenge: Using a test-first approach, and without resorting to any text books, or Google, or looking at the sources of existing regular expression implementations, write a simple regular expression matcher that supports the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;c&lt;/tt&gt;: literal character &lt;tt&gt;c&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;.&lt;/tt&gt; (period): any single character&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;^&lt;/tt&gt;: beginning of input string&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;$&lt;/tt&gt;: end of input string&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;*&lt;/tt&gt;: zero or more occurrences of the previous character&lt;/li&gt;
&lt;/ul&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2007/08/17/friday_java_challenge_write_a_regular_expression_parser.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2007/08/17/friday_java_challenge_write_a_regular_expression_parser.html</guid>
    <pubDate>Fri, 17 Aug 2007 12:41:20 GMT</pubDate>
  </item>
  
  <item>
    <title>Refactoring Is Garbage Collection Of The Source</title>
    <link>http://www.weiqigao.com/blog/2005/09/20/refactoring_is_garbage_collection_of_the_source.html</link>
    
      
        <description>
          &lt;p&gt;We are doing another round of refactoring in my current project.  This is one of those biggish refactorings that changes the code structure for the better.  We&#039;ve done this before (as I &lt;a href= &#034;http://www.weiqigao.com/blog/2005/01/28/how_many_xp_practices_do_you_follow.html&#034; &gt;blogged 235 days ago&lt;/a&gt;.)  And here&#039;s some of our thoughts on the matter of refactoring, especially &lt;span style=&#034;color:red&#034;&gt;big refactoring&lt;/span&gt;.&lt;/p&gt;

&lt;hr noshade=&#034;noshade&#034; size=&#034;1&#034; width=&#034;60%&#034;&gt;

&lt;p&gt;According to Rob, as you code by adding new features and fixing bugs, the tension in the code increases.  It is wise to do refactorings from time to time to release the tension so that the code base remains pliable.  This is very important for the continued success of the code base.&lt;/p&gt;

&lt;hr noshade=&#034;noshade&#034; size=&#034;1&#034; width=&#034;60%&#034;&gt;

&lt;p&gt;Big refactorings, as opposed to regular refactorings that you do as you code, is rather like garbage collection (of the mark and sweep kind) in that i) you stop everything else in the code base to do it; ii) the code base will be cleaner afterwards so that you can code more efficiently.&lt;/p&gt;

&lt;hr noshade=&#034;noshade&#034; size=&#034;1&#034; width=&#034;60%&#034;&gt;

&lt;p&gt;Here&#039;s another analogy: If the entire product is a quilt and each individual features are the piece parts, then regular refactoring can be thought of as ironing out the pieces before stitching them onto the quilt and big refactoring can be though of as ironing out the while quilt.  Both are necessary.  One doesn&#039;t imply the other.  I&#039;m tempted to call them &lt;span style=&#034;color:red&#034;&gt;local&lt;/span&gt; refactorings and &lt;span style=&#034;color:red&#034;&gt;global&lt;/span&gt; refactorings.&lt;/p&gt;

&lt;hr noshade=&#034;noshade&#034; size=&#034;1&#034; width=&#034;60%&#034;&gt;

&lt;p&gt;Of course, all these refactoring is made possible by the unit tests and functional tests that we have written.  We are not yet &#034;test first&#034; on this project, but we spend quite a lot of time (almost 1:1) writing tests.&lt;/p&gt;

&lt;p&gt;Writing tests is such a natural part of the project that time for writing tests are part of the estimates for each feature: &#034;4 hours to write the code, 4 hours to write the tests.&#034;  Tests are not skimmed even when we are up against a deadline:&lt;/p&gt;

&lt;div style=&#034;margin-left:3em&#034;&gt;
&lt;p&gt;&lt;b&gt;Jonathan&lt;/b&gt;: I can finished the code before COB today.  Do you want me to check in the code?&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Kevin&lt;/b&gt;: You want to check in &lt;em&gt;broken&lt;/em&gt; code?&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Jonathan&lt;/b&gt;: They aren&#039;t broken.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Kevin&lt;/b&gt;: Prove it!&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Jonathan&lt;/b&gt;: &lt;em&gt;(Lost for words. ...)&lt;/em&gt; I can write the tests later.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Rob&lt;/b&gt;: Write the tests &lt;em&gt;now&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;hr noshade=&#034;noshade&#034; size=&#034;1&#034; width=&#034;60%&#034;&gt;

&lt;center&gt;
&lt;p style=&#034;font-size:xx-large;font-family:sans-serif&#034;&gt;We&lt;span style=&#034;color:red&#034;&gt;&amp;hearts;&lt;/span&gt;&lt;b&gt;Tests&lt;/b&gt;&lt;/p&gt;
&lt;/center&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2005/09/20/refactoring_is_garbage_collection_of_the_source.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2005/09/20/refactoring_is_garbage_collection_of_the_source.html</guid>
    <pubDate>Wed, 21 Sep 2005 03:00:12 GMT</pubDate>
  </item>
  
  </channel>
</rss>

