function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BobPBobP 

Code coverage error 71% need 75%

I've been trying to add more criteria to pass the code coverage to move a trigger to production but my test class doesn't pass the the coverage test. I don't know how much more criteria I can add.  Any help with this would be greatly appreciated. 

 
@IsTest
public class TestAfterPOLogUpdateTest {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        
        test.startTest();
        
        Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Yushin_Product__c.getRecordTypeInfosByName();
        List<String> recordTypeNames = new List<String>(recordTypes.keyset());
        
        
        
        PageReference pageRef = Page.OppTabDetailinsidesales2;
        
          
          
        Contact c= new Contact();
        
        c.FirstName ='Bob';
        c.LastName = 'Poliquin';
        c.Email = 'Acme@aol.com';
        c.Phone = '5088084748';
        
        insert c;
        
        
           
        Account a = new Account();
         a.Name = 'Test';
         a.Industry = 'Retail';
         a.Territory_Code__c='KY';
         a.Sales_Agency__c='Five Nines - Plastics Division';
         insert a;
        
        Opportunity o = new Opportunity();
         o.name = 'Test';
         o.AccountId = a.Id;
         o.StageName = 'Closed Won';
         o.CloseDate = date.today();
         o.Type = 'New Customers';
         o.Product_Type__c = 'Robot';
         
        
         insert o;
         
                
        
         Product2 prod = new Product2(Name = 'HOP Five 900X', 
                                     Robot_Category__c = 'Hardware',Standard_Price__c=12345);
        insert prod;
        
        Id pricebookId = Test.getStandardPricebookId();
        
        PricebookEntry standardPrice = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = prod.Id,
            UnitPrice = 10000, IsActive = true);
        
         insert standardPrice;
         
         Request_for_Special_Payment__c rsp = new Request_for_Special_Payment__c ();  

         rsp.Opportunity_Name__c = o.Id;
         rsp.Account__c = a.Id;
         rsp.Requestor_Submit_for_Approval__c = true;
         rsp.Request_Submitted_By__c = 'Bob Poliquin';
         rsp.Requestor_Date_Submitted__c=date.today();
            
         insert rsp;
            
            
         rsp.Opportunity_Name__c = o.Id;
         rsp.Supervisor_Approved__c = true;
         rsp.Rejected_By__c='Chris Parillo';
         rsp.Supervisor_Approval_Date__c=date.today();
            
         update rsp;
            
            

        PO_Log__c p = new PO_Log__c();
	
         p.Customer__c=a.Id;
         p.Opportunity__c=o.Id;
	     p.Order_Type__c='EOAT'; 
         insert p;
      
         p.Opportunity__c= o.Id;
         p.PO__c = '1223';
         p.Sales_Order_Number__c = '12453';
         p.Order_Type__c = 'Robot';
         p.Notes__c= 'text';
         p.Order_Configuration__c = 'ATC';
         p.Sales_Order_Number__c = '189345';
         p.AddPLogOpps__c = true;
      
         update p;
         
                 
       

        Yushin_Product__c ypd = new Yushin_Product__c(Discharge_Direction__c='Clamp Traverse');
        
         ypd.Opportunity__c=o.id;
         ypd.Account__c =a.Id; 
         ypd.Discharge_Direction__c='Clamp Traverse';
         ypd.IMM_Mfr__c='Arburg';
         ypd.IMM_Model__c='NT450';
         ypd.Plant_Voltage__c='110';
         ypd.Interface_Voltage__c='110 VDC';
         ypd.Equipment_Type__c = 'Robot';
         ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
         
        
         insert ypd;
        
       
         ypd.Account__c =a.Id ; 
         ypd.Discharge_Direction__c='Clamp Traverse';
         ypd.IMM_Mfr__c='Engel';
         ypd.IMM_Model__c='110t';
         ypd.Plant_Voltage__c='110';
         ypd.Interface_Voltage__c='110 VDC';
         ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
        
        update ypd;
        
        
        ypd.Equipment_Type__c = 'Other';
          ypd.Product_Detail_Report__c = 'Misc. Item';
          ypd.SPI_Reported__c=false;
          ypd.Date_Booked__c = Date.newInstance(2016, 12, 9);
          ypd.Date_Entered__c = Date.newInstance(2016, 12, 8);
          ypd.Sales_Order_Number__c = '1910678';
          ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
         
          
          update ypd;
        
        
          ypd.Equipment_Type__c = 'Installation';
          ypd.Product_Detail_Report__c = 'Installation';
          ypd.SPI_Reported__c=false;
          ypd.Date_Booked__c = Date.newInstance(2016, 12, 9);
          ypd.Date_Entered__c = Date.newInstance(2016, 12, 8);
          ypd.Sales_Order_Number__c = '1910678';
          ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
         
          
          update ypd;
          
          ypd.Equipment_Type__c = 'EOAT';
          ypd.Price__c = 499;
          ypd.Model__c='HOP 750';
          ypd.Status__c ='Quoted';
          ypd.Date_Booked__c = Date.newInstance(2016, 12, 9);
          ypd.Date_Entered__c = Date.newInstance(2016, 12, 8);
          
          
         
         
          update ypd;
           
          
          ypd.Equipment_Type__c = 'Safety Guarding';
          ypd.Product_Detail_Report__c = 'AUTO-SM';
          ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
          
         
          update ypd;
          
          
          ypd.Equipment_Type__c = 'Conveyor';
          ypd.Price__c =45080;
          ypd.Status__c ='Sold';
          ypd.Date_Booked__c = Date.newInstance(2016, 12, 9);
          ypd.Date_Entered__c = Date.newInstance(2016, 12, 8);
          ypd.Quantity__c= 1;
          ypd.Product_Detail_Report__c = 'AUTO-SM';
          ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
          
          
          update ypd;
           
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'Servo Trav over 600';
          ypd.Model__c='FRA-1530S-22-11-C1  ';
          ypd.Status__c ='Sold';
          ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
          
          
          update ypd;
           
         
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'Adapter Plate';
          ypd.Product_Detail_Report__c='Misc. Item';
          ypd.Status__c ='Sold';
          ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
          
          update ypd;
           
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'A-Axis';
          ypd.Product_Detail_Report__c='EOAT-SM';
          ypd.RecordTypeId = recordTypes.get(recordTypeNames[0]).getRecordTypeId();
          ypd.Status__c ='Sold';
         
          update ypd;
          
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'B-Axis';
          
          ypd.Status__c ='Sold';
         
          update ypd;
           
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'Freight';
          ypd.Product_Detail_Report__c='Freight';
          
          update ypd;
           
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'Degating Station';
          ypd.Product_Detail_Report__c='AUTO-SM';
          ypd.Status__c ='Sold';
           
          
          update ypd;
           
          ypd.Equipment_Type__c = 'Installation';
          ypd.Product_Detail_Report__c='Installation';
          ypd.Status__c ='Sold';
           
         
          update ypd;
           
          ypd.Equipment_Type__c = 'Hybrid';
          ypd.Product_Detail_Report__c='SM-Hybrid';
          
          ypd.Status__c ='Sold';
         
          
          update ypd;
           
          ypd.Equipment_Type__c = 'Software';
          ypd.Product_Detail_Report__c='Software';
          ypd.Status__c ='Sold';
           
         
          update ypd;
           
          ypd.Equipment_Type__c = 'Servo Traverse Super Large 1300 and greater';
          ypd.Model__c='RAII-a-3000SL';
          
          ypd.Status__c ='Sold';
          
          update ypd;
           
          ypd.Equipment_Type__c = 'Spacer';
          ypd.Product_Detail_Report__c='Misc. Item';
          ypd.Status__c ='Sold';
           
         
          update ypd;
           
          ypd.Equipment_Type__c = 'Stanchion';
          ypd.Status__c ='Quoted';
           
          
          update ypd;
          
          ypd.Equipment_Type__c = 'Servo Trav over 600';
          ypd.Model__c='YCII-800D-30-18';
          ypd.Product_Detail_Report__c='LG-YC';
          
          ypd.Status__c ='Sold';
          
          update ypd;
           
          ypd.Equipment_Type__c = 'System - SMALL';
          ypd.Product_Detail_Report__c='AUTO-SM';
          ypd.Status__c ='Sold';
          
         
          update ypd;
           
          ypd.Equipment_Type__c = 'Collaborative robot';
          ypd.Model__c='OB7';
          ypd.Product_Detail_Report__c='SPECIAL';
          ypd.Status__c ='Sold';
           
          
          update ypd;
           
          ypd.Equipment_Type__c = 'Side-entry (horz)';
          ypd.Model__c='SVR B50';
          ypd.Product_Detail_Report__c='SM-SE';
          
          update ypd;
           
          ypd.Equipment_Type__c = 'Side-entry (Vert)';
          ypd.Product_Detail_Report__c='SM-SE';
          
          ypd.Status__c ='Sold';
      
          update ypd;
           
          ypd.Equipment_Type__c = 'Parts';
          ypd.Product_Detail_Report__c='Misc. Item';
          ypd.Status__c ='Sold';
           
        
          update ypd;
          
          ypd.Equipment_Type__c = 'Safety Guarding';
          ypd.Product_Detail_Report__c='AUTO-SM';
          
          ypd.Status__c ='Sold';
         
          update ypd;
          
          ypd.Equipment_Type__c = 'System - MEDIUM';
          ypd.Product_Detail_Report__c='AUTO-SM';
          
          ypd.Status__c ='Quoted';
          ypd.Order_Config__c = 'Systems';
          ypd.Order_Type__c = 'Systems';
         
          update ypd;
               
          
           
                  
          

      

      test.stopTest();
    }
}




 
Best Answer chosen by BobP
Steven NsubugaSteven Nsubuga
You already implemented that in the test, just copy and paste from the test.
trigger TriggerNewYushinProd on Opportunity ( after insert, after update) {
    
    List<Yushin_Product__c> yus = new List<Yushin_Product__c>();
    List<Yushin_Product__c> yusToDelete = new List<Yushin_Product__c>();
    
    Map<Id, List<Yushin_Product__c>> existingYusMap = new Map<Id, List<Yushin_Product__c>>();
	
	Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Yushin_Product__c.getRecordTypeInfosByName();
	
    
    for(Yushin_Product__c yu :[SELECT Id, Opportunity__c, Account__c, Equipment_Type__c from Yushin_Product__c where Opportunity__c IN :Trigger.newMap.keyset()]){
        List<Yushin_Product__c> yushinProducts = existingYusMap.get(yu.Opportunity__c);
        if (yushinProducts == null) {
            yushinProducts = new List<Yushin_Product__c>();
        }
        yushinProducts.add(yu);
        existingYusMap.put(yu.Opportunity__c, yushinProducts);
    }
    
    
    
    for(Opportunity o : Trigger.new)  {
        if (Trigger.IsInsert || Trigger.oldMap.get(o.Id).Product_Type__c == null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot'; 
                y.RecordTypeId = recordTypes.get('RecordTypeId1').getRecordTypeId();
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains( 'EOAT'))                
            {
                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';
                y.RecordTypeId = recordTypes.get('RecordTypeId2').getRecordTypeId();               
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId = recordTypes.get('RecordTypeId3').getRecordTypeId();
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Other'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Other';
                y.RecordTypeId = recordTypes.get('RecordTypeId4').getRecordTypeId();
                yus.add(y);
            }
        }
        else if (Trigger.IsUpdate && Trigger.oldMap.get(o.Id).Product_Type__c != null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot';
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId(); 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Robot')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Robot') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('EOAT') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';  
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId();                 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('EOAT')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'EOAT') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId();
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Conveyor')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Conveyor') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Safety Guarding') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Safety Guarding';
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId();
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Safety Guarding')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Safety Guarding') {
                        yusToDelete.add(yP);
                    }
                }
            }
        }
    }  
 
    if(yus.size()>0)
        insert yus;
    if(yusToDelete.size()>0)
        database.delete(yusToDelete);
}

 

All Answers

Matt Brown 71Matt Brown 71
Can you share your Apex class?  That should help us help you!
Mario PariseMario Parise
Hi Bob,

How are you running your tests? If you use the Developer Console, you can run your tests and discover which lines of code are and aren't being tested.

Code coverage is simply a count that shows how much of your code is actually being run in a test. If you're getting 71%, that means 29% of your code isn't being touched by the tests you've written so far.

By running these tests in the console and seeing which lines aren't being run, you can determine what scenarios you need to devise in order to cross that 75% threshold.

Hope this helps!
BobPBobP
Below is my trigger. I didnt want to hard code record id's but I'm not sure how accomplish that. 
 
trigger TriggerNewYushinProd on Opportunity ( after insert, after update) {
    
    List<Yushin_Product__c> yus = new List<Yushin_Product__c>();
    List<Yushin_Product__c> yusToDelete = new List<Yushin_Product__c>();
    
    Map<Id, List<Yushin_Product__c>> existingYusMap = new Map<Id, List<Yushin_Product__c>>();
    
    for(Yushin_Product__c yu :[SELECT Id, Opportunity__c, Account__c, Equipment_Type__c from Yushin_Product__c where Opportunity__c IN :Trigger.newMap.keyset()]){
        List<Yushin_Product__c> yushinProducts = existingYusMap.get(yu.Opportunity__c);
        if (yushinProducts == null) {
            yushinProducts = new List<Yushin_Product__c>();
        }
        yushinProducts.add(yu);
        existingYusMap.put(yu.Opportunity__c, yushinProducts);
    }
    
    
    
    for(Opportunity o : Trigger.new)  {
        if (Trigger.IsInsert || Trigger.oldMap.get(o.Id).Product_Type__c == null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot'; 
                y.RecordTypeId='012390000006Dve';               
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains( 'EOAT'))                
            {
                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';
                y.RecordTypeId='012390000006Dva';               
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId='012390000006DvZ';
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Other'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Other';
                y.RecordTypeId='012390000006Dve';
                yus.add(y);
            }
        }
        else if (Trigger.IsUpdate && Trigger.oldMap.get(o.Id).Product_Type__c != null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot';
                y.RecordTypeId='012390000006Dve'; 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Robot')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Robot') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('EOAT') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';  
                y.RecordTypeId='012390000006Dva';                 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('EOAT')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'EOAT') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId='012390000006DvZ';
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Conveyor')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Conveyor') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Safety Guarding') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Safety Guarding';
                y.RecordTypeId='012390000006Dvb';
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Safety Guarding')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Safety Guarding') {
                        yusToDelete.add(yP);
                    }
                }
            }
        }
    }  
 
    if(yus.size()>0)
        insert yus;
    if(yusToDelete.size()>0)
        database.delete(yusToDelete);
}

 
BobPBobP
Her eis some of the code that is not covered

User-added image
Mario PariseMario Parise
Ah, I suspect the hardcoded RecordTypeIds are the issue.

When a test is run, it actually creates entirely new test data. RecordTypes included. So the Ids you're looking for do not exist.

Instead, you'll have to update your apex to go grab the RecordTypeId, like so:
 
Id rtId = Schema.SObjectType.ContentVersion.getRecordTypeInfosByName().get('Record Type Name Goes Here').getRecordTypeId();

...replacing "ContentVersion" with your ObjectType (such as Account, Contact, Product, whatever) and 'Record Type Name Goes Here' with your actual Record Type name.
BobPBobP
How can I the code below to work for more than one record type? would i re-create this code for every record type?

Id rtId = Schema.SObjectType.ContentVersion.getRecordTypeInfosByName().get('Record Type Name Goes Here').getRecordTypeId();
Steven NsubugaSteven Nsubuga
You already implemented that in the test, just copy and paste from the test.
trigger TriggerNewYushinProd on Opportunity ( after insert, after update) {
    
    List<Yushin_Product__c> yus = new List<Yushin_Product__c>();
    List<Yushin_Product__c> yusToDelete = new List<Yushin_Product__c>();
    
    Map<Id, List<Yushin_Product__c>> existingYusMap = new Map<Id, List<Yushin_Product__c>>();
	
	Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Yushin_Product__c.getRecordTypeInfosByName();
	
    
    for(Yushin_Product__c yu :[SELECT Id, Opportunity__c, Account__c, Equipment_Type__c from Yushin_Product__c where Opportunity__c IN :Trigger.newMap.keyset()]){
        List<Yushin_Product__c> yushinProducts = existingYusMap.get(yu.Opportunity__c);
        if (yushinProducts == null) {
            yushinProducts = new List<Yushin_Product__c>();
        }
        yushinProducts.add(yu);
        existingYusMap.put(yu.Opportunity__c, yushinProducts);
    }
    
    
    
    for(Opportunity o : Trigger.new)  {
        if (Trigger.IsInsert || Trigger.oldMap.get(o.Id).Product_Type__c == null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot'; 
                y.RecordTypeId = recordTypes.get('RecordTypeId1').getRecordTypeId();
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains( 'EOAT'))                
            {
                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';
                y.RecordTypeId = recordTypes.get('RecordTypeId2').getRecordTypeId();               
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId = recordTypes.get('RecordTypeId3').getRecordTypeId();
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Other'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Other';
                y.RecordTypeId = recordTypes.get('RecordTypeId4').getRecordTypeId();
                yus.add(y);
            }
        }
        else if (Trigger.IsUpdate && Trigger.oldMap.get(o.Id).Product_Type__c != null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot';
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId(); 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Robot')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Robot') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('EOAT') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';  
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId();                 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('EOAT')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'EOAT') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId();
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Conveyor')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Conveyor') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Safety Guarding') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Safety Guarding';
                y.RecordTypeId=recordTypes.get('RecordTypeId1').getRecordTypeId();
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Safety Guarding')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Safety Guarding') {
                        yusToDelete.add(yP);
                    }
                }
            }
        }
    }  
 
    if(yus.size()>0)
        insert yus;
    if(yusToDelete.size()>0)
        database.delete(yusToDelete);
}

 
This was selected as the best answer
Mario PariseMario Parise
Hey Bob, Steven's right, you implemented it in Test. But yes, you could repeat that method for each RecordTypeId that you need to get.
BobPBobP
Thanks yo for helping all,

I updated my test class and trigger which improved the coverage but not by much. I dont understand why certain parts of the trigger is covered and other parts are not.  See my screen shot below. 

User-added image

My Updated Trigger: Should I add  test for deleted records?
 
trigger TriggerNewYushinProd on Opportunity ( after insert, after update) {
    
    List<Yushin_Product__c> yus = new List<Yushin_Product__c>();
    List<Yushin_Product__c> yusToDelete = new List<Yushin_Product__c>();
    
    Map<Id, List<Yushin_Product__c>> existingYusMap = new Map<Id, List<Yushin_Product__c>>();
	
	Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Yushin_Product__c.getRecordTypeInfosByName();
	
    
    for(Yushin_Product__c yu :[SELECT Id, Opportunity__c, Account__c, Equipment_Type__c from Yushin_Product__c where Opportunity__c IN :Trigger.newMap.keyset()]){
        List<Yushin_Product__c> yushinProducts = existingYusMap.get(yu.Opportunity__c);
        if (yushinProducts == null) {
            yushinProducts = new List<Yushin_Product__c>();
        }
        yushinProducts.add(yu);
        existingYusMap.put(yu.Opportunity__c, yushinProducts);
    }
    
    
    
    for(Opportunity o : Trigger.new)  {
        if (Trigger.IsInsert || Trigger.oldMap.get(o.Id).Product_Type__c == null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot'; 
                y.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains( 'EOAT'))                
            {
                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';
                y.RecordTypeId = recordTypes.get('EOAT').getRecordTypeId();               
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId = recordTypes.get('Conveyor').getRecordTypeId();
                yus.add(y);
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Other'))               
            {                
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Other';
                y.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
                yus.add(y);
            }
        }
        else if (Trigger.IsUpdate && Trigger.oldMap.get(o.Id).Product_Type__c != null) {
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Robot';
                y.RecordTypeId=recordTypes.get('Robot').getRecordTypeId(); 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Robot')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Robot') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('EOAT') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='EOAT';  
                y.RecordTypeId=recordTypes.get('EOAT').getRecordTypeId();                 
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('EOAT')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'EOAT') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Conveyor';
                y.RecordTypeId=recordTypes.get('Conveyor').getRecordTypeId();
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Conveyor')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Conveyor') {
                        yusToDelete.add(yP);
                    }
                }
            }
            
            if(o.Product_Type__c != null && o.Product_Type__c.contains('Safety Guarding') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))                    
            {                    
                Yushin_Product__c y=new Yushin_Product__c();
                y.Opportunity__c=o.Id;
                y.Account__c=o.AccountId; 
                y.Equipment_Type__c='Safety Guarding';
                y.RecordTypeId=recordTypes.get('Safety Guarding').getRecordTypeId();
                yus.add(y);
            }
            
            if((o.Product_Type__c == null || !o.Product_Type__c.contains('Safety Guarding')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding'))
            {
                List<Yushin_Product__c> yPs = existingYusMap.get(o.Id);
                for (Yushin_Product__c yP : yPs) {
                    if (yP.Equipment_Type__c == 'Safety Guarding') {
                        yusToDelete.add(yP);
                    }
                }
            }
        }
    }  
 
    if(yus.size()>0)
        insert yus;
    if(yusToDelete.size()>0)
        database.delete(yusToDelete);
}


Updated Test Class:
 
@IsTest
public class TestAfterPOLogUpdateTest {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        
        test.startTest();
        
        Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Yushin_Product__c.getRecordTypeInfosByName();
        List<String> recordTypeNames = new List<String>(recordTypes.keyset());
        
        
        
        PageReference pageRef = Page.OppTabDetailinsidesales2;
        
          
          
        Contact c= new Contact();
        
        c.FirstName ='Bob';
        c.LastName = 'Poliquin';
        c.Email = 'Acme@aol.com';
        c.Phone = '5088084748';
        
        insert c;
        
        
           
        Account a = new Account();
         a.Name = 'Test';
         a.Industry = 'Retail';
         a.Territory_Code__c='KY';
         a.Sales_Agency__c='Five Nines - Plastics Division';
         insert a;
        
        Opportunity o = new Opportunity();
         o.name = 'Test';
         o.AccountId = a.Id;
         o.StageName = 'Closed Won';
         o.CloseDate = date.today();
         o.Type = 'New Customers';
         o.Product_Type__c = 'Robot';
         
        
         insert o;
         
                
        
         Product2 prod = new Product2(Name = 'HOP Five 900X', 
                                     Robot_Category__c = 'Hardware',Standard_Price__c=12345);
        insert prod;
        
        Id pricebookId = Test.getStandardPricebookId();
        
        PricebookEntry standardPrice = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = prod.Id,
            UnitPrice = 10000, IsActive = true);
        
         insert standardPrice;
         
         Request_for_Special_Payment__c rsp = new Request_for_Special_Payment__c ();  

         rsp.Opportunity_Name__c = o.Id;
         rsp.Account__c = a.Id;
         rsp.Requestor_Submit_for_Approval__c = true;
         rsp.Request_Submitted_By__c = 'Bob Poliquin';
         rsp.Requestor_Date_Submitted__c=date.today();
            
         insert rsp;
            
            
         rsp.Opportunity_Name__c = o.Id;
         rsp.Supervisor_Approved__c = true;
         rsp.Rejected_By__c='Chris Parillo';
         rsp.Supervisor_Approval_Date__c=date.today();
            
         update rsp;
            
            

        PO_Log__c p = new PO_Log__c();
	
         p.Customer__c=a.Id;
         p.Opportunity__c=o.Id;
	     p.Order_Type__c='EOAT'; 
         insert p;
      
         p.Opportunity__c= o.Id;
         p.PO__c = '1223';
         p.Sales_Order_Number__c = '12453';
         p.Order_Type__c = 'Robot';
         p.Notes__c= 'text';
         p.Order_Configuration__c = 'ATC';
         p.Sales_Order_Number__c = '189345';
         p.AddPLogOpps__c = true;
      
         update p;
         
                 
       

        Yushin_Product__c ypd = new Yushin_Product__c();
        
          ypd.Opportunity__c=o.id;
          ypd.Account__c =a.Id; 
          ypd.Discharge_Direction__c='Clamp Traverse';
          ypd.IMM_Mfr__c='Arburg';
          ypd.IMM_Model__c='NT450';
          ypd.Plant_Voltage__c='110';
          ypd.Interface_Voltage__c='110 VDC';
          ypd.Equipment_Type__c = 'Servo Trav 600 and under';
          ypd.Model__c='HST-150S-22-85-EII';
          ypd.Product_Detail_Report__c ='SM-RC';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
         
        
          insert ypd;
        
       
          ypd.Account__c =a.Id ; 
          ypd.Discharge_Direction__c='Clamp Traverse';
          ypd.IMM_Mfr__c='Engel';
          ypd.IMM_Model__c='110t';
          ypd.Plant_Voltage__c='110';
          ypd.Interface_Voltage__c='110 VDC';
          ypd.Equipment_Type__c = 'Servo Trav 600 and under';
          ypd.Model__c='RC-70S-14-7';
          ypd.Product_Detail_Report__c ='SM-RC';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
        
          update ypd;
        
         
          ypd.Account__c =a.Id; 
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'Servo Trav over 600';
          ypd.Model__c='FRA-1530S-22-11-C1  ';
          ypd.Product_Detail_Report__c ='SM-FRA';
          ypd.Status__c ='Sold';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
          
          
          update ypd;
           
          
          ypd.Account__c =a.Id; 
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'Adapter Plate';
          ypd.Product_Detail_Report__c='Misc. Item';
          ypd.Status__c ='Sold';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
          
          update ypd;
           
          
          ypd.Account__c =a.Id;
          ypd.Price__c =45080;
          ypd.Equipment_Type__c = 'Freight';
          ypd.Product_Detail_Report__c='Freight';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
          
          update ypd;
          
          
          ypd.Equipment_Type__c = 'Servo Traverse Super Large 1300 and greater';
          ypd.Model__c='RAII-a-3000SL';
          ypd.Status__c ='Sold';
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
          
          update ypd;
           
                  
          ypd.Equipment_Type__c = 'Servo Trav over 600';
          ypd.Model__c='YCII-800D-30-18';
          ypd.Product_Detail_Report__c='LG-YC';
          ypd.Status__c ='Sold';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
          
          update ypd;
          
          
          ypd.Equipment_Type__c = 'Collaborative robot';
          ypd.Model__c='OB7';
          ypd.Product_Detail_Report__c='SPECIAL';
          ypd.Status__c ='Sold';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
           
          update ypd;
           
          
          ypd.Equipment_Type__c = 'Side-entry (horz)';
          ypd.Model__c='SVR B50';
          ypd.Product_Detail_Report__c='SM-SE';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
          
          update ypd;
           
          ypd.Equipment_Type__c = 'Side-entry (Vert)';
          ypd.Product_Detail_Report__c='SM-SE';
          ypd.Status__c ='Sold';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
      
          update ypd;
          
          ypd.Equipment_Type__c = 'Spacer';
          ypd.Product_Detail_Report__c='Misc. Item';
          ypd.Status__c ='Sold';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
           
         
          update ypd;
           
          
          ypd.Equipment_Type__c = 'Stanchion';
          ypd.Status__c ='Quoted';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.Sales_Order_Number__c = '1910678';
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
           
          
          update ypd;
        
           
          ypd.Account__c =a.Id;
          ypd.Equipment_Type__c = 'Other';
          ypd.Product_Detail_Report__c = 'Misc. Item';
          ypd.SPI_Reported__c=false;
          ypd.Sales_Order_Number__c = '1910678';
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
         
          
          update ypd;
        
          ypd.Account__c =a.Id; 
          ypd.Equipment_Type__c = 'Installation';
          ypd.Product_Detail_Report__c = 'Installation';
          ypd.SPI_Reported__c=false;
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.Sales_Order_Number__c = '1910678';
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
         
          
          update ypd;
          
          
          ypd.Equipment_Type__c = 'Hybrid';
          ypd.Product_Detail_Report__c='SM-Hybrid';
          ypd.Date_Entered__c = System.today() ;
          ypd.Date_Booked__c = System.today() +5;
          ypd.Status__c ='Sold';
          ypd.RecordTypeId = recordTypes.get('Robot').getRecordTypeId();
         
          
          update ypd;
          
          
          ypd.Equipment_Type__c = 'Software';
          ypd.Product_Detail_Report__c='Software';
          ypd.Status__c ='Sold';
           
         
          update ypd;
           
          
           
          ypd.Equipment_Type__c = 'System - SMALL';
          ypd.Product_Detail_Report__c='AUTO-SM';
          ypd.Status__c ='Sold';
          
         
          update ypd;
          
          ypd.Equipment_Type__c = 'System - MEDIUM';
          ypd.Product_Detail_Report__c='AUTO-MD';
          ypd.Status__c ='Quoted';
          ypd.Order_Config__c = 'Systems';
          ypd.Order_Type__c = 'Systems';
         
          update ypd;
          
          ypd.Equipment_Type__c = 'System - LARGE';
          ypd.Product_Detail_Report__c='AUTO-LG';
          ypd.Status__c ='Quoted';
          ypd.Order_Config__c = 'Systems';
          ypd.Order_Type__c = 'Systems';
         
          update ypd;
          
          
          Yushin_Product__c e = new Yushin_Product__c();
          
          e.Opportunity__c=o.id;
          e.Account__c =a.Id; 
          e.Equipment_Type__c = 'EOAT';
          e.Product_Detail_Report__c='EOAT-SM';
          e.Price__c = 499;
          e.Model__c='';
          e.Status__c ='Quoted';
          e.Date_Entered__c = System.today() ;
          e.Date_Booked__c = System.today() +5;
          e.RecordTypeId = recordTypes.get('EOAT').getRecordTypeId();
          
          
          insert e;
           
            
          e.Account__c =a.Id; 
          e.Price__c =45080;
          e.Equipment_Type__c = 'A-Axis';
          e.Product_Detail_Report__c='EOAT-SM';
          e.RecordTypeId = recordTypes.get('EOAT').getRecordTypeId();
          e.Status__c ='Sold';
         
          update e;
          
          
          e.Account__c=a.Id; 
          e.Price__c =45080;
          e.Equipment_Type__c = 'B-Axis';
          e.Status__c ='Sold';
          e.RecordTypeId = recordTypes.get('EOAT').getRecordTypeId();
         
          update e;
          
          e.Account__c =a.Id;
          e.Price__c =45080;
          e.Equipment_Type__c = 'Degating Station';
          e.Product_Detail_Report__c='AUTO-SM';
          e.Status__c ='Sold';
          e.RecordTypeId = recordTypes.get('EOAT').getRecordTypeId();
           
          
          update e;
          
          Yushin_Product__c s = new Yushin_Product__c();
          
          s.Opportunity__c=o.id;
          s.Account__c =a.Id; 
          s.Equipment_Type__c = 'Safety Guarding';
          s.Product_Detail_Report__c = 'AUTO-SM';
          s.Price__c = 120000;
          s.Target_In_mold_Take_out_Time_Seconds__c = 52;
          s.Target_Overall_Cycle_Time_Seconds__c = 60;
          s.Straight_off_mold__c ='yes';
          s.Do_Parts_Fall__c= 'No';
          s.Quantity__c=2;
          s.RecordTypeId = recordTypes.get('Safety Guarding').getRecordTypeId();
          
         
          insert s;
          
          
          s.Account__c =a.Id; 
          s.Equipment_Type__c = 'Safety Guarding';
          s.Product_Detail_Report__c = 'AUTO-SM';
          s.Price__c = 42000;
          s.Target_In_mold_Take_out_Time_Seconds__c = 10;
          s.Target_Overall_Cycle_Time_Seconds__c = 80;
          s.Straight_off_mold__c ='yes';
          s.Do_Parts_Fall__c= 'Yes';
          s.Quantity__c=2;
          s.RecordTypeId = recordTypes.get('Safety Guarding').getRecordTypeId();
          
          update s;
          
          Yushin_Product__c cv = new Yushin_Product__c();
          
          cv.Opportunity__c=o.id;
          cv.Account__c =a.Id; 
          cv.Equipment_Type__c = 'Conveyor';
          cv.Price__c =45080;
          cv.Status__c ='Sold';
          cv.Height__c = '15';
          cv.Length__c = '42';
          cv.Date_Entered__c = System.today() ;
          cv.Date_Booked__c = System.today() +5;
          cv.Quantity__c= 1;
          cv.Product_Detail_Report__c = 'AUTO-SM';
          cv.RecordTypeId = recordTypes.get('Conveyor').getRecordTypeId();
          
          
          insert cv;
          
           cv.Account__c =a.Id; 
          cv.Equipment_Type__c = 'Conveyor';
          cv.Price__c =22000;
          cv.Status__c ='Sold';
          cv.Date_Entered__c = System.today() ;
          cv.Date_Booked__c = System.today() +5;
          cv.Quantity__c= 2;
          cv.Product_Detail_Report__c = 'AUTO-MD';
          cv.RecordTypeId = recordTypes.get('Conveyor').getRecordTypeId();
          
          
          update cv;
           
                     
                    
                     
                    

      

      test.stopTest();
    }
}


 
Mario PariseMario Parise
(...I had answered and realized I was mistaken, so I deleted my previous comment. Apologies if you got notified of the wrong answer. Let me try this again.)

As best as I can tell, your trigger is looking for the Product Type on the Opportunity itself. Although you insert and update many products, you appear to keep using the same opportunity. That opportunity has a Product Type of "Robot", so the "Robot" part of your code is run. You never change the opportunity itself, so the Product Type on it never changes.

I would recomment creating a new opportunity for every product you're testing. I believe that would fix the issue.
BobPBobP
Thank you Mario,

 I will try that solution.
BobPBobP
Thank you all for helping me with this request! Mario your comments were helpful, but I'm doing to mark Steven's last post as Best Answer. 

Thanks again everyone!