title: What is the best approach for Unit testing when you have interfaces with both dummy & real implementations?
body: <p>I'm familiar with the basic principles of TDD, being :</p>
  
  <ol>
  <li>Write tests, these will fail because of no implementation</li>
  <li>Write basic implementation to make tests pass</li>
  <li>Refactor code</li>
  </ol>
  
  <p>However, I'm a little confused as to where interfaces and implementation fit. I'm creating a Spring web application in my spare time, and rather than going in guns blazing, I'd like to understand how I can test interfaces/implementations a little better, take this simple example code I've created here :</p>
  
  <pre><code>public class RunMe
  {
  
      public static void main(String[] args)
      {
          // Using a dummy service now, but would have a real implementation later (fetch from DB etc.)
          UserService userService = new DummyUserService();
          System.out.println(userService.getUserById(1));
      }
  }
  
  interface UserService
  {
      public String getUserById(Integer id);
  }
  
  class DummyUserService implements UserService
  {
      @Override
      public String getUserById(Integer id)
      {
          return "James";
      }
  }
  </code></pre>
  
  <p>I've created the <code>UserService</code> interface, ultimately there will be a real implementation of this that will query a database, however in order to get the application off the ground I've substituted a <code>DummyUserService</code> implementation that will just return some static data for now.</p>
  
  <p><strong>Question : How can I implement a testing strategy for the above?</strong></p>
  
  <p>I could create a test class called <code>DummyUserServiceTest</code> and test that when I call <code>getUserById()</code> it'll return <code>James</code>, seems pretty simple if not a waste of time(?).</p>
  
  <p>Subsequently, I could also create a test class <code>RealUserService</code> that would test that <code>getUserById()</code> returns a users name from the database. This is the part that confuses me slightly, in doing so, does this not essentially overstep the boundary of a unit test and become more of an intergration test (with the hit on the DB)?</p>
  
  <p><strong>Question (improved, a little): When using interfaces with dummy/stubbed, and real implementations, which parts should be unit tested, and which parts can safely be left untested?</strong></p>
  
  <p><em>I spent a few hours Googling on this topic last night, and mostly found either tutorials on what TDD is, or examples of how to use JUnit, but nothing in the realms of advising what should actually be tested. It is entirely possible though, that I didn't search hard enough or wasn't looking for the right thing...</em></p>