title: How to write test code before write source code when they are objects dependencies?
body: <p>I'l will take an example:<br> <strong>requirement</strong>: construct a piece of material following these rule: <br>among given &lt; 100 => material is green<br>
  100 &lt; among &lt;300=> material is yellow<br>
  among > 300=> material is red<br></p>
  
  <p>My test class:<br></p>
  
  <pre><code>        class MaterialTest{
            MaterialConstructor materialCons
            public void testBuild(){
                   materialCons.setAmount(150);
                   Material material=materialCons.build();
                   assertEqual(material.getColor(),"Yellow");
                }
      }
  </code></pre>
  
  <p>From know i don't how to implemented materialCons.build(); After design and analysis i've implemented MaterialCosntructor  as follow:</p>
  
  <pre><code>    public class MaterialConstructor {
  
           private Helper1 helper1;
           private Helper2 helper2
  
          MaterialConstructor (Helper1 help1, Helper2 help2){
        .................   
      }
  
      public Material build(Double among){
           part1=helper1.builpart(among);
          return helper2.construct(part1);
      }
  
  }
  </code></pre>
  
  <p>In my initial test class i must includes code like this:</p>
  
  <pre><code>helper1=createMock(Helper1)
  helper2=createMock(Helper2)
  
  materialCons=new MaterialConstructor (helper1, helper2)
  
  .....................
  
  expected(helper1.builpart(150)).andReturn(some result)
  expected(helper2.construct(some result)).andReturn("Yellow")
  </code></pre>
  
  <p>as result we can get this updated class test:</p>
  
  <pre><code>  class MaterialTest{
           MaterialConstructor materialCons
          public void testBuild(){
              helper1=createMock(Helper1)
              helper2=createMock(Helper2)
              materialCons=new MaterialConstructor (helper1, helper2)
              expected(helper1.builpart(150)).andReturn(some result)
              expected(helper2.construct(some result)).andReturn("Yellow")
               materialCons.setAmount(150);
               Material material=materialCons.build();
               assertEqual(material.getColor(),"Yellow");
  
            }
              }
  </code></pre>
  
  <p>hence my test code will be update after writen my source code!</p>
  
  <p>This will appear many time ( since it's difficult at specification time to know which dependencies class you must use to solve your problem). Then unit-test class will be always obsolete after written source code!</p>