title: How do we write unit tests for methods which involves connection with DB?
body: <p>I have been having a query regarding writing unit tests for web methods which actually communicates with a database and returns some value.</p>
  
  <p>Say for example I have a web service named "StudentInfoService".
  That web serivces provides a API "getStudentInfo(studentid)"</p>
  
  <p>Here is some sample snippet </p>
  
  <pre><code>public class StudentInfoService
  {
      public StudentInfo getStudentInfo(long studentId) {
              //Communicates with DB and creates
              // StudentInfo object with necessary information
              // and returns it to the caller.
      }
  }
  </code></pre>
  
  <p>How do we actually write unit tests for this method getStudentInfo? 
  Generally how do we write unit tests for methods which involves a connection with a resource(Database, Files, JNDI, etc...)?</p>