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
Jordan TorreyJordan Torrey 

One test pass - one test failed - Have no idea how to fix the issue

so ive got 83 objects im testing for. My positive test method fails - while my negative test case passes. The positive case stops at object 81, and i cant figure out why its not iterating all the way through to 83....It may be pretty obvious, as im still new to apex development. Any advice would be more than welcome. Thanks in advance. 
P.S. I removed some of the objects from the sample code as I've hit the character limit - so please feel free to reach out to me with any questions or concerns.
@isTest 
public class DynamicDataCapture {
   
       static Aexp_Enrollment__c objEnroll;  
    public static void setup(){
        
        List<AEXP_Dynamic_Data_Capture__c> lstobjDDC = new List<AEXP_Dynamic_Data_Capture__c>();
        
		objEnroll = new Aexp_Enrollment__c();
		objEnroll.Opportunity__c = '0064B000003bdRA';
		insert objEnroll;
        
        AEXP_Dynamic_Data_Capture__c objDDC = new AEXP_Dynamic_Data_Capture__c();	
        
        objDDC.Display_When__c = '';
        objDDC.Element_Id__c = '49';
        objDDC.Element_Label__c = 'Legal Company Name';
        objDDC.Element_Type__c = 'Text';
        objDDC.Element_Value__c = 'Dreamforce';
        objDDC.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC.Field_Sort_Id__c = '1';
        objDDC.isRequired__c = True;
        objDDC.Max_Length__c = 100;
        objDDC.Section_Name__c = 'Legal Company Information';
        objDDC.Section_Sort_Id__c = '';
        
        
        lstobjDDC.add(objDDC); //<-- Add object one to the list
        
        AEXP_Dynamic_Data_Capture__c objDDC2 = new AEXP_Dynamic_Data_Capture__c();  //<-- Object 2
        
        objDDC2.Display_When__c = '';
        objDDC2.Element_Id__c = '59';
        objDDC2.Element_Label__c = 'Comapny Name(Doing Business As)';
        objDDC2.Element_Type__c = 'text';
        objDDC2.Element_Value__c = 'Dreamforce';
        objDDC2.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC2.Field_Sort_Id__c = '1';
        objDDC2.isRequired__c = False;
        objDDC2.Max_Length__c = 100;
        objDDC2.Section_Name__c = 'Legal Company Information';
        objDDC2.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC2); //<-- Add object 2 to the list
        
        AEXP_Dynamic_Data_Capture__c objDDC3 = new AEXP_Dynamic_Data_Capture__c(); //<--Object 3
        
        objDDC3.Display_When__c = '';
        objDDC3.Element_Id__c = '50';
        objDDC3.Element_Label__c = 'Tax ID Number (TIN)';
        objDDC3.Element_Type__c = 'Text';
        objDDC3.Element_Value__c = '4567899';
        objDDC3.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC3.Field_Sort_Id__c = '3';
        objDDC3.isRequired__c = True;
        objDDC3.Max_Length__c = 16;
        objDDC3.Section_Sort_Id__c ='1';
        objDDC3.Section_Name__c ='Legal Company Information';
        
        lstobjDDC.add(objDDC3);
        
        AEXP_Dynamic_Data_Capture__c objDDC4 = new AEXP_Dynamic_Data_Capture__c(); //<-- Object 4
        
        objDDC4.Display_When__c = '';
        objDDC4.Element_Id__c = '60';
        objDDC4.Element_Label__c = 'Dun & Bradstreet Number';
        objDDC4.Element_Type__c = 'Text';
        objDDC4.Element_Value__c = '456789';
        objDDC4.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC4.Field_Sort_Id__c = '4';
        objDDC4.isRequired__c = False;
        objDDC4.Max_Length__c = 9;
        objDDC4.Section_Name__c = 'Legal Company Information';
        objDDC4.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC4);
        
        AEXP_Dynamic_Data_Capture__c objDDC5 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC5.Display_When__c = '';
        objDDC5.Element_Id__c = '51';
        objDDC5.Element_Label__c = 'Corporate Phone Number';
        objDDC5.Element_Type__c = 'Text';
        objDDC5.Element_Value__c = '(876) 545-6787';
        objDDC5.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC5.Field_Sort_Id__c = '5';
        objDDC5.isRequired__c = True;
        objDDC5.Max_Length__c = 40;
        objDDC5.Section_Name__c = 'Legal Company Information';
        objDDC5.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC5);
        
        AEXP_Dynamic_Data_Capture__c objDDC6 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC6.Display_When__c = '';
        objDDC6.Element_Id__c = 'Date of Incorprotation';
        objDDC6.Element_Type__c = 'Text';
        objDDC6.Element_Value__c = '5/1/2016';
        objDDC6.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC6.Field_Sort_Id__c = '6';
        objDDC6.isRequired__c = True;
        objDDC6.Max_Length__c = 10;
        objDDC6.Section_Name__c = 'Legal Comapny Information';
        objDDC6.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC6);
        
        AEXP_Dynamic_Data_Capture__c objDDC7 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC7.Display_When__c = '';
        objDDC7.Element_Id__c = '52';
        objDDC7.Element_Label__c = 'Corporate Headquarter Address';
        objDDC7.Element_Type__c = 'Text Area';
        objDDC7.Element_Value__c = '23456 N 44 St';
        objDDC7.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC7.Field_Sort_Id__c = '7';
        objDDC7.isRequired__c = True;
        objDDC7.Max_Length__c = 25;
        objDDC7.Section_Name__c = 'Legal Company Name';
        objDDC7.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC7);
        
        AEXP_Dynamic_Data_Capture__c objDDC8 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC8.Display_When__c = '';
        objDDC8.Element_Id__c = '62';
        objDDC8.Element_Label__c = 'Country of Incorporation';
        objDDC8.Element_Type__c = 'Text';
        objDDC8.Element_Value__c = 'USA';
        objDDC8.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC8.Field_Sort_Id__c = '8';
        objDDC8.isRequired__c = True;
        objDDC8.Max_Length__c = 80;
        objDDC8.Section_Name__c = 'Legal Comapny Information';
        objDDC8.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC8);
        
        AEXP_Dynamic_Data_Capture__c objDDC9 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC9.Display_When__c = '';
        objDDC9.Element_Id__c = '54';
        objDDC9.Element_Label__c = 'City';
        objDDC9.Element_Type__c = 'Text';
        objDDC9.Element_Value__c = 'Phoenix';
        objDDC9.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC9.Field_Sort_Id__c = '9';
        objDDC9.isRequired__c = True;
        objDDC9.Max_Length__c = 80;
        objDDC9.Section_Name__c = 'Legal Company Information';
        objDDC9.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC9);
        
        AEXP_Dynamic_Data_Capture__c objDDC10 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC10.Display_When__c = '';
        objDDC10.Element_Id__c = '65';
        objDDC10.Element_Label__c = 'State of Incorportation';
        objDDC10.Element_Type__c = 'Text';
        objDDC10.Element_Value__c = 'Arizona';
        objDDC10.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC10.Field_Sort_Id__c = '10';
        objDDC10.isRequired__c = False;
        objDDC10.Max_Length__c = 80;
        objDDC10.Section_Name__c = 'Legal Company Information';
        objDDC10.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC10);
        
        AEXP_Dynamic_Data_Capture__c objDDC11 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC11.Display_When__c = '';
        objDDC11.Element_Id__c = '56';
        objDDC11.Element_Label__c = 'Stat';
        objDDC11.Element_Type__c = 'Text';
        objDDC11.Element_Value__c = 'Arizona';
        objDDC11.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC11.Field_Sort_Id__c = '11';
        objDDC11.isRequired__c = True;
        objDDC11.Max_Length__c = 80;
        objDDC11.Section_Name__c = 'Legal Company Information';
        objDDC11.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC11);
        
        AEXP_Dynamic_Data_Capture__c objDDC12 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC12.Display_When__c = '';
        objDDC12.Element_Id__c = '64';
        objDDC12.Element_Label__c = 'Website';
        objDDC12.Element_Type__c = 'text';
        objDDC12.Element_Value__c = 'www.force.com';
        objDDC12.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC12.Field_Sort_Id__c = '12';
        objDDC12.isRequired__c = True;
        objDDC12.Max_length__c = 255;
        objDDC12.Section_Name__c = 'Legal Comapny Information';
        objDDC12.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC12);
        
        AEXP_Dynamic_Data_Capture__c objDDC13 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC13.Display_When__c = '';
        objDDC13.Element_Id__c = '57';
        objDDC13.Element_Label__c = 'Zip';
        objDDC13.Element_Type__c = 'Text';
        objDDC13.Element_Value__c = '85027';
        objDDC13.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC13.Field_Sort_Id__c = '13';
        objDDC13.isRequired__c = True;
        objDDC13.Max_Length__c = 9;
        objDDC13.Section_Name__c = 'Lagal Company Information';
        objDDC13.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC13);
        
        AEXP_Dynamic_Data_Capture__c objDDC14 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC14.Display_When__c = '';
        objDDC14.Element_Id__c = '63';
        objDDC14.Element_Label__c = 'Client Type';
        objDDC14.Element_Type__c = 'Text';
        objDDC14.Element_Value__c = 'New';
        objDDC14.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC14.Field_Sort_Id__c = '1';
        objDDC14.isRequired__c = True;
        objDDC14.Max_Length__c = 40;
        objDDC14.Section_Name__c = 'Legal Company Information';
        objDDC14.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC14);
        
        AEXP_Dynamic_Data_Capture__c objDDC15 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC15.Display_When__C = '';
        objDDC15.Element_Id__c = '53';
        objDDC15.Element_Label__c = 'Corporate Headquarter Address Line 2';
        objDDC15.Element_Type__c = 'Text';
        objDDC15.Element_Value__c = '';
        objDDC15.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC15.Field_Sort_Id__c = '1011';
        objDDC15.isRequired__c = False;
        objDDC15.Max_Length__c = 40;
        objDDC15.Section_Name__c = 'Legal Comapny Information';
        objDDC15.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC15);
        
        AEXP_Dynamic_Data_Capture__c objDDC16 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC16.Display_When__c = '';
        objDDC16.Element_Id__c = '58';
        objDDC16.Element_Label__c = 'SFDC Opportunity ID';
        objDDC16.Element_Type__c = 'Text';
        objDDC16.Element_Value__c = '0064B000003bdRAQAY';
        objDDC16.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC16.Field_Sort_Id__c = '1024';
        objDDC16.isRequired__c = False;
        objDDC16.Max_Length__c = 25;
        objDDC16.Section_Name__c = 'Legal Comapny Information';
        objDDC16.Section_Sort_Id__c = '1';
        
        lstobjDDC.add(objDDC16);
        
        AEXP_Dynamic_Data_Capture__c objDDC17 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC17.Display_When__c = '';
        objDDC17.Element_Id__c = '43';
        objDDC17.Element_Label__c = 'Company Type';
        objDDC17.Element_Type__c = 'Text';
        objDDC17.Element_Value__c = 'Private';
        objDDC17.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC17.Field_Sort_Id__c = '1';
        objDDC17.isRequired__c = True;
        objDDC17.Max_Length__c = 40;
        objDDC17.Section_Name__c = 'Corporate Demograpihc';
        objDDC17.Section_Sort_Id__c = '2';
        
        lstobjDDC.add(objDDC17);
      
// <This is where I deleted the rest of the objects > 
        
    
        
        AEXP_Dynamic_Data_Capture__c objDDC81 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC81.Display_When__c = '';
        objDDC81.Element_Id__c = '75';
        objDDC81.Element_Label__c = 'Zip';
        objDDC81.Element_Type__c = 'Text';
        objDDC81.Element_Value__c = '85027';
        objDDC81.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC81.Field_Sort_Id__c = '16';
        objDDC81.isRequired__c = False;
        objDDC81.Max_Length__c = 20;
        objDDC81.Section_Name__c = 'Master Program Administrator';
        objDDC81.Section_Sort_Id__c = '8';
        
        lstobjDDC.add(objDDC81);
        
        AEXP_Dynamic_Data_Capture__c objDDC82 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC82.Display_When__c = '';
        objDDC82.Element_Id__c = '76';
        objDDC82.Element_Label__c = 'Country';
        objDDC82.Element_Type__c = 'Text';
        objDDC82.Element_Value__c = 'USA';
        objDDC82.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC82.Field_Sort_Id__c = '17';
        objDDC82.isRequired__c = False;
        objDDC82.Max_Length__c = 80;
        objDDC82.Section_Name__c = 'Master Program Administrator';
        objDDC82.Section_Sort_Id__c = '8';
        
        lstobjDDC.add(objDDC82);
        
        AEXP_Dynamic_Data_Capture__c objDDC83 = new AEXP_Dynamic_Data_Capture__c();
        
        objDDC83.Display_When__c = '';
        objDDC83.Element_Id__c = '72';
        objDDC83.Element_Label__c = 'Address Line 2';
        objDDC83.Element_Type__c = 'Text';
        objDDC83.Element_Value__c = '';
        objDDC83.Enrollment__c =objEnroll.id; //'a694B00000003wdQAA';
        objDDC83.Field_Sort_Id__c = '1005';
        objDDC83.isRequired__c = False;
        objDDC83.Max_Length__c = 40;
        objDDC83.Section_Name__c = 'Master Program Administrator';
        objDDC83.Section_Sort_Id__c = '8';
        
        lstobjDDC.add(objDDC83);
              system.debug('Obj::::'+lstobjDDC.size());  
        try{
            
            Database.insert(lstobjDDC);
        }
        catch(DmlException e){
            system.debug('Exception: '+e.getMessage());
        }
    }
         
    
         //-------------------------------------------------------------------
         // Beginning of test methods - Positive/Negative
    
    	

        public static testMethod void testPositiveTestCases(){
        
        setup();

           Test.startTest();   
        
            List<AEXP_Dynamic_Data_Capture__c> lstDDC = new List<AEXP_Dynamic_Data_Capture__c>();
            lstDDC = [Select Id from AEXP_Dynamic_Data_Capture__c where Enrollment__c = :objEnroll.id];
           system.debug('lst:::::'+ lstDDC.size());
            System.assert(lstDDC.size() == 83);
             
            
        Test.stopTest();
                   
        //Add each variable name to the test case method
        
        lstDDC = [Select Element_Label__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Display_When__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83 );
        
        lstDDC = [Select Element_Id__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Element_Type__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Element_Value__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Enrollment__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Field_Sort_Id__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select isRequired__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Max_Length__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Picklist_Values__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDc = [Select Section_Name__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >=83);
        
        lstDDC = [Select Section_Sort_Id__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);       
        
          
      
    
    }
    
    
	     static testMethod void testNegativeTestCases() {
        
        setup();
        Test.startTest();   
        List<AEXP_Dynamic_Data_Capture__c> lstDDC1 = new List<AEXP_Dynamic_Data_Capture__c>();
            lstDDC1 = [Select Id from AEXP_Dynamic_Data_Capture__c where Enrollment__c = 'a694B00000003wdQAA' ];
            system.assert(lstDDC1.size() != 83);
            
        Test.stopTest();
             
             
        List<AEXP_Dynamic_Data_Capture__c> lstDDC = new List<AEXP_Dynamic_Data_Capture__c>();
        
        
        lstDDC = [Select Element_Label__c from  AEXP_Dynamic_Data_Capture__c];
       system.assert(lstDDC.size() >=83);
        
        lstDDC = [Select Display_When__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Element_Id__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Element_Type__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Element_Value__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Enrollment__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Field_Sort_Id__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select isRequired__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Max_Length__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Picklist_Values__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
        
        lstDDC = [Select Section_Sort_Id__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83);
             
        lstDDC = [Select Section_Name__c from AEXP_Dynamic_Data_Capture__c];
        system.assert(lstDDC.size() >= 83); 
       
        
    } 
				
    
}
Here is what is showing up in the debug log:
11:16:25:586 USER_DEBUG [1377]|DEBUG|lst:::::81

Here is the test log:
System.AssertException: Assertion Failed
Class.DynamicDataCapture.testPositiveTestCases: line 1378, column 1
Jordan TorreyJordan Torrey
Here - Line 1378 will be shown as line 360/361