title: Is it necessary to code unit tests for every single layer on an n-tier architecture?
body: <p>I'm new to Unit Tests so I've been trying to code some examples to learn the right way to use them. I have an example project which uses Entity Framework to connect to a database. </p>
  
  <p>I'm using an n-tier architecture composed by a data access layer which queries the database using EF, a business layer which invokes data access layer methods to query database and perform its business purpose with the data retrieved and a service layer which is composed of  WCF services that simply invoke business layer objects.</p>
  
  <p>Do I have to code unit tests for every single layer (data access, business layer, services layer? </p>
  
  <p>Which would be the right way to code a unit test for a method that queries a database? The next code is an example of a method in my data access layer which performs a select on the database, how should its unit test be like?</p>
  
  <pre><code>public class DLEmployee
  {
  
      private string _strErrorMessage = string.Empty;
      private bool _blnResult = true;
  
      public string strErrorMessage
      {
          get
          {
              return _strErrorMessage;
          }
      }
      public bool blnResult
      {
          get
          {
              return _blnResult;
          }
      }
  
      public Employee GetEmployee(int pintId)
      {
          Employee employee = null;
          _blnResult = true;
          _strErrorMessage = string.Empty;
  
          try
          {
              using (var context = new AdventureWorks2012Entities())
              {
                  employee = context.Employees.Where(e =&gt; e.BusinessEntityID == pintId).FirstOrDefault();
              }
          }
          catch (Exception ex)
          {
              _strErrorMessage = ex.Message;
              _blnResult = false;
  
          }
  
          return employee;
      }
  </code></pre>