title: C# stubbing. Interface for every testable object?
body: <p>I've seen multiple answers regarding 'how to stub your classes so you can control what happens  within the SUT'.</p>
  
  <p>They say one thing:</p>
  
  <blockquote>
    <blockquote>
      <p>Create an interface and inject that interface using dependency injection and create a stub using that same interface that you then inject into the SUT.</p>
    </blockquote>
  </blockquote>
  
  <p>However, what I've learned in my previous working places:</p>
  
  <blockquote>
    <blockquote>
      <p>If you unit test, you test <em>all</em> classes/functionality.</p>
    </blockquote>
  </blockquote>
  
  <p>Does that mean that for every class that has a specific function-layout you have to create an interface?</p>
  
  <p>That would mean the amount of classes/files would just about be twice as many.</p>
  
  <p>As seen in the example below, is this 'the way to go' or am I missing something in my unit testing process?</p>
  
  <p>As a note:
  I am using VS2012 Express. That means no 'Faker' framework. I am using the 'standard' VS2012 unit testing framework.</p>
  
  <p>As a very, very simple example, which allows me to stub each interface passed down to a SUT.</p>
  
  <p><strong>IFoo.cs</strong>  </p>
  
  <pre><code>public interface IFoo
  {
      string GetName();
  }
  </code></pre>
  
  <p><strong>Foo.cs</strong>  </p>
  
  <pre><code>public class Foo : IFoo
  {
      public string GetName()
      {
          return "logic goes here";
      }
  }
  </code></pre>
  
  <p><strong>IBar.cs:</strong></p>
  
  <pre><code>public interface IBar : IFoo
  {
      IFoo GetFoo();
  }
  </code></pre>
  
  <p><strong>Bar.cs:</strong></p>
  
  <pre><code>public class Bar : IBar
  {
      public string GetName()
      {
          return "logic goes here";
      }
  
      public IFoo GetFoo()
      {
          return null; // some instance of IFoo
      }
  }
  </code></pre>
  
  <p><strong>IBaz.cs:</strong></p>
  
  <pre><code>public interface IBaz
  {
      IBar GetBar();
  }
  </code></pre>
  
  <p><strong>Baz.cs:</strong></p>
  
  <pre><code>public class Baz
  {
      public IBar GetBar()
      {
          return null; // some instance of IBar
      }
  }
  </code></pre>