title: Unit Testing how I think to point logical mistake on class which is under test
body: <p>I m reading Art of Unit testing book and I try to understand state based testing logic.In an example of subject there was a calculator class like</p>
  
  <pre><code>public class Calculator
  {
      private int sum=0;
      public void Add(int number)
      {
        sum+=number;
      }
      public int Sum()
      {
        int temp = sum;
        sum = 0;
        return temp;
      }
   }
  </code></pre>
  
  <p>and book shows how can we test this as:</p>
  
  <pre><code>[TestFixture]
  public class CalculatorTests
  {
      private Calculator calc;
  
      [SetUp]
      public void Setup()
      {
          calc = new Calculator();
      }
  
      [Test]
      public void Sum_NoAddCalls_DefaultsToZero()
      {
          int lastSum = calc.Sum();
          Assert.AreEqual(0,lastSum);
      }
  
      [Test]
      public void Add_CalledOnce_SavesNumberForSum()
      {
          calc.Add(1);
          int lastSum = calc.Sum();
          Assert.AreEqual(1,lastSum);
      }
  
      [Test]
      public void Sum_AfterCall_ResetsToZero()
      {
          calc.Add(1);
          calc.Sum();
          int lastSum = calc.Sum();
          Assert.AreEqual(0, lastSum);
      }
  
  }
  </code></pre>
  
  <p>So until this, everything is great but, lets say I m writing a calculator class as much as that class, and i made method like</p>
  
  <pre><code>public int Sum()
  {
  
    return sum;
  
  }
  </code></pre>
  
  <p>and <BR>
  Test class like <br></p>
  
  <pre><code> [TestFixture]
  public class CalculatorTests
  {
      private Calculator calc;
  
      [SetUp]
      public void Setup()
      {
          calc = new Calculator();
      }
  
      [Test]
      public void Sum_NoAddCalls_DefaultsToZero()
      {
          int lastSum = calc.Sum();
          Assert.AreEqual(0,lastSum);
      }
  
      [Test]
      public void Add_CalledOnce_SavesNumberForSum()
      {
          calc.Add(1);
          int lastSum = calc.Sum();
          Assert.AreEqual(1,lastSum);
      }
  }
  </code></pre>
  
  <p>Let say I didnt good realize when i writing code and when i write unit test for that How I catch that following bug? Because bug is that sum will not be zero after 2 add method like following processes </p>
  
  <pre><code>add(1)
  add(23)
  sum()  is 24 now
  add(11)
  add(12)
  sum()  =&gt; will be 47 but it has to be 23.
  </code></pre>
  
  <p>So how i think to get that logical mistake when i write unit test.(if i write it NUnit will tell me there is a mistake) then i come back and will see the point and I will change calculator class like</p>
  
  <pre><code>public int Sum() 
  { 
    int temp = sum; 
    sum = 0; 
    return temp; 
  }
  </code></pre>
  
  <p><br>
  I hope you understand what i try to say.<br>
  Thanks. </p>