+ Start a Discussion
sandeepathadusandeepathadu 

plz help with test case

this is my trigger

 

trigger updatetotal on Opportunity (before update, before insert)
{
    Integer i = 0;
    Decimal id2num =0.00;
   Decimal n1=0.00;Decimal n2=0.00,n3=0.00,n4=0.00;
    for (Opportunity o : Trigger.new)
    {
  
   if (Trigger.isUpdate)
        {
   Opportunity[] opp =[select ID,Total_Approved__c,Total_Invoiced__c,Total_Planned__c,Total_Submitted__c,StageName,Amount from Opportunity where Header_Opportunity__c=:o.id and  recordtypeid='012M000000008mu' and StageName='Billing-Invoiced'];
     
     o.Total_Invoiced__c=0.00;
     o.Total_Approved__c=0.00;
     o.Total_Planned__c=0.00;
     o.Total_Submitted__c=0.00;
     
     
        for(Opportunity opp1:opp)
         {              
           n1=opp1.Amount+n1;
           o.Total_Invoiced__c=n1;         
         }
        
     Opportunity[] opp3 =[select ID,Total_Approved__c,Total_Invoiced__c,Total_Planned__c,Total_Submitted__c,StageName,Amount from Opportunity where Header_Opportunity__c=:o.id and  recordtypeid='012M000000008mu' and StageName='Billing-Approved' ];
     for(Opportunity opp13:opp3) 
        {
          n2=opp13.Amount+n2;
          o.Total_Approved__c=n2;}
       
       
     Opportunity[] opp7 =[select ID,Total_Approved__c,Total_Invoiced__c,Total_Planned__c,Total_Submitted__c,StageName,Amount from Opportunity where Header_Opportunity__c=:o.id and  recordtypeid='012M000000008mu' and StageName='Billing-Planned' ];
        
           for(Opportunity opp17:opp7){ 
           n3=opp17.Amount+n3;
           o.Total_Planned__c=n3;
          }
         Opportunity[] opp9 =[select ID,Total_Approved__c,Total_Invoiced__c,Total_Planned__c,Total_Submitted__c,StageName,Amount from Opportunity where Header_Opportunity__c=:o.id and  recordtypeid='012M000000008mu' and  StageName='Billing-Submitted' ];
          for(Opportunity opp19:opp9){ 
          n4=opp19.Amount+n4;
          o.Total_Submitted__c=n4;
          }
      }

       }
     
    }
my test case and i am getting only 68 percent code coverage plz help
@istest
private class updatetotal_Test1 {

  //  static testMethod void SetContactRoleDefaults_Test() {
  //  test.starttest();
  static testMethod void uptotal ()
  {
            Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
           
            Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
            insert pb;
            
            Product2 prod = new Product2(Name = 'Anti-infectives 2007', Family = 'Best Practices', IsActive = true);
            insert prod;
            
            PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = standardPB.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
            insert standardPrice;
            
            PricebookEntry pbe = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
            insert pbe;
            
            //List <Account> Account ;
            Account a = new account();
            a.Name = 'Powerhouse Electronics';
            insert a;
            
           // Product prod = new Product();
           // prod.Name = 'Product test';
           // insert prod;
            
            //header opportunity
            Opportunity p = new Opportunity();
            p.Name = 'Testing9';
            p.Accountid= a.id;           
            p.ForecastCategoryName='Commit'; 
            p.recordtypeid='012M000000008mp';
            p.StageName='Billing-Approved';
            p.Amount=1000; 
            p.Total_Approved__c=100;
            
            p.CloseDate = date.ValueOf('2009-07-21');
           p.Estimated_Start_Date__c=date.ValueOf('2009-7-21');
           p .Estimated_End_Date__c=date.ValueOf('2009-10-21');
            p.StageFilter__c = 'Billing-Approved';                    
            insert p;
             update p;
            
             decimal n1=0.0;
              n1=p.Amount+100;
              p.Total_Approved__c=n1;
             
              
              
             decimal n2=0.0;
              n2=p.Amount+100;
              p.Total_Planned__c=n1;
             
            
            OpportunitylineItem olitem = new OpportunitylineItem();
            olitem.opportunityid=p.id;
            olitem.TotalPrice=56;
            olitem.quantity=33;
            olitem.PricebookEntryId =pbe.id;          
            insert olitem;
            
            
            Opportunity p1 = new Opportunity();
            p1.Header_Opportunity__c=p.id;
            p1.Name='test9';
            p1.StageName='Billing-Approved';
            p1.recordtypeid='012M000000008mp';
            p1.CloseDate=Date.valueof('2011-07-07');            
            insert p1;
             update p; 
             OpportunitylineItem olitem1 = new OpportunitylineItem();
             olitem1.opportunityid=p1.id;
             olitem1.TotalPrice=56;
             olitem1.quantity=33;
             
             olitem1.PricebookEntryId = pbe.id;        
             insert olitem1; 
              
             
          
  
  
   

                                                
    }
 
}