title: unit testing public methods with tested internal methods
body: <p>I find myself falling into this pattern quite a lot, I write a class composed of very small methods which are completely exercised by my unit tests. Then I find I need to build another method that calls these methods and I have to write a more complicated unit test for that – a simple example would be illustrative:</p>
  
  <pre><code>namespace FooRequest
  {
      static public class Verifier
      {
          static public bool IsValid(string request)
          {
              return (!IsAllCaps(request) &amp;&amp; !ContainsTheLetterB(request));
          }
  
          static internal bool IsAllCaps(string request)
          {
              return (request.Equals(request.ToUpper()));
          }
  
          static internal bool ContainsTheLetterB(string request)
          {
              return request.ToLower().Contains("b");
          }
      }
  }
  </code></pre>
  
  <p>For code I’d write unit tests to cover the two internal methods like this:</p>
  
  <pre><code>namespace UnitTest
  {
      using Microsoft.VisualStudio.TestTools.UnitTesting;
      using FooRequest;
  
      public class VerifierTest
      {
          [TestClass]
          public class ContainsTheLetterB
          {
              [TestMethod]
              public void ShouldReturnTrueForStringContainsB()
              {
                  Assert.IsTrue(Verifier.ContainsTheLetterB("burns"));
              }
  
              [TestMethod]
              public void ShouldReturnFakseForStringDoesNotContainB()
              {
                  Assert.IsFalse(Verifier.ContainsTheLetterB("urns"));
              }
          }
  
          [TestClass]
          public class IsAllCaps
          {
              [TestMethod]
              public void ShouldReturnTrueForStringIsAllCaps()
              {
                  Assert.IsTrue(Verifier.IsAllCaps("IAMALLCAPS"));
              }
  
              [TestMethod]
              public void ShouldReturnFakseForStringDoesNotContainB()
              {
                  Assert.IsFalse(Verifier.IsAllCaps("IAMnotALLCAPS"));
              }
          }
      }
  }
  </code></pre>
  
  <p>For the public method I really just want to test “if the methods you call return false, then return false” – it’s annoying that I have to set up the input in such a way to force my internal methods to return true or false – my test for this method shouldn’t care about the internal methods it calls (right?)</p>
  
  <pre><code>    [TestClass]
      public class IsValid
      {
          [TestMethod]
          public void ShouldReturnFalseForInvalidStringBecauseContainsB()
          {
              Assert.IsFalse(Verifier.IsValid("b"));
          }
  
          [TestMethod]
          public void ShouldReturnFalseForInvalidStringBecauseIsAllCaps()
          {
              Assert.IsFalse(Verifier.IsValid("CAPS"));
          }
  
          [TestMethod]
          public void ShouldReturnTrueForValidString()
          {
              Assert.IsTrue(Verifier.IsValid("Hello"));
          }
      }
  </code></pre>
  
  <p>Obviously for this example, that’s not too bad, but when there are lots of internal methods and the input is non-trivial to configure, testing my public “Is This Input Valid” method gets complicated.</p>
  
  <p>Should I create an interface for all my internal methods then stub it out for the tests or is there a neater way?</p>