title: How to get the code coverage required to deploy Apex Class
body: <p>Please Help!!!
  I have this Apex controller class that I'm trying to deploy from Salesforce Sandbox to Production but I'm not getting the code coverage required!!</p>
  
  <p>the class is consuming 3 objects, one is stranded and 2 are custom and constructing a hierarchy tree view for those three objects.</p>
  
  <p>//Apex Class</p>
  
  <p>public class TeeView {</p>
  
  <pre><code>        /* Wrapper class to contain the nodes and their children */
   public class cNodes
  {
      Public StandardObject gparent {get;set;}
      public List&lt;CustomObject1__c&gt; parent {get; set;}
      Public List&lt;CustomObject2__c&gt; child {get;set;}
  
      public cNodes(StandardObject   gp, List&lt;CustomObject1__c&gt; p, List&lt;CustomObject2__c&gt; c)
      {
      parent = p;
      gparent = gp;
      child = c;
      }
  }
  
          /* end of Wrapper class */ 
  
  Public List&lt;cNodes&gt; hierarchy;
  
  Public List&lt;cNodes&gt; getmainnodes()
  {
      hierarchy = new List&lt;cNodes&gt;();
      List&lt;StandardObject&gt; tempparent = [Select Id,Name  , End_Date__c, Owner.Name Account.Name from Contract ];
      for (Integer i =0; i&lt; tempparent.size() ; i++)
          {
          List&lt;CustomObject1__c&gt; tempchildren = [Select Id,Name, Owner.Name , (select Id,Name, Owner.Name from CustomObject2__r)  from CustomObject1__c where    Related_Field__c = :tempparent[i].Id];
          List&lt;CustomObject2__c&gt; tempchild = [Select Id,Name Owner.Name from CustomObject2__c where    Related_Field__c= :tempparent[i].Id];
  
          hierarchy.add(new cNodes(tempparent[i],tempchildren, tempchild));
          }   
      return hierarchy;
  }  
  </code></pre>
  
  <p>}</p>
  
  <p>//Test Class
  @isTest
  public class treeviewTest
  {</p>
  
  <pre><code>static testMethod void test1()
  {
      test.startTest();
  
  
      Account acc = new Account(Name = 'Unit test account');
      insert acc;
  
      StandardObject c = new StandardObject(
          Name = 'test',
          AccountId = acc.Id,
          Status = 'Draft',
          StartDate = System.today());
      try
      {
          insert c;
      }
      catch (Exception ex)
      {
          ApexPages.addMessages(ex);
      }
  
      List&lt;StandardObject&gt; standard = [select Id, Name from StandardObject where Name = 'test'];
      system.assertequals(standard.size(), 1);
  
      CustomObject1__c s = new CustomObject1__c(
          Related_StandardObjectField__c = c.Id,
          Name = 'test'
      );
      try
      {
          insert s;
      }
      catch (Exception ex)
      {
          ApexPages.addMessages(ex);
      }
  
      List&lt;CustomObject1__c&gt; cus1 = [select Id, Name from CustomObject1__c where Name = 'test'];
      system.assertequals(cus1.size(), 1);
  
      insert new CustomObject2__c(Related_StandardObjectField__c = c.Id, Description__c = 'test');
      List&lt;CustomObject2__c&gt; cus2 = [select Id, Name from CustomObject2__c where Description__c = 'test'];
      system.assertequals(cus2.size(), 1);
  
      insert new CustomObject2__c(Related_CustomObject1Field__c = s.Id, Description__c = 'test');
      List&lt;Mods__c&gt; cus3 = [select Id, Name from Mods__c where Description__c = 'test'];
      system.assertequals(cus3.size(), 1);
  
      treeView view = new treeView();
  
      view.getmainnodes();
  
  
      test.stopTest();
  }
  </code></pre>
  
  <p>}</p>