+ Start a Discussion
m 3m 3 

Could you please help me apex class i am posting below any body help me code need to write test class code average

public without sharing class N_ContactImport_Table {
  @AuraEnabled public List<Column> columns;
    @AuraEnabled public List<ContactWrapper> contactWrapperList;
    @AuraEnabled public String cData;
    @AuraEnabled public String next_link;
    
    public class Column {
        @AuraEnabled public String data;
        @AuraEnabled public String type;
        @AuraEnabled public String title;
    }
    
    public class ContactWrapper {
        @AuraEnabled public Contact contact;
        @AuraEnabled public Integer rowNumber;
        @AuraEnabled public String id; //this refers to ConstantContact List ID.
    }
}
AshishkAshishk
Try below:-
@isTest
private class TestN_ContactImport_Table {
 
    static  testmethod void test1(){
        N_ContactImport_Table a=new N_ContactImport_Table ();
        system.debug(a.columns);
        system.debug(a.contactWrapperList);
        system.debug(a.cData);
        system.debug(a.next_link);
    }
}
But this way only your class will be covered, try to add complete use case in test method so that you can assert the output.

Thanks

 
Raj VakatiRaj Vakati
Class 
public without sharing class N_ContactImport_Table {
    @AuraEnabled public List<Column> columns{get;set;}
    @AuraEnabled public List<ContactWrapper> contactWrapperList{get;set;}
    @AuraEnabled public String cData{get;set;}
    @AuraEnabled public String next_link{get;set;}
    
    public class Column {
        @AuraEnabled public String data;
        @AuraEnabled public String type;
        @AuraEnabled public String title;
    }
    
    public class ContactWrapper {
        @AuraEnabled public Contact contact;
        @AuraEnabled public Integer rowNumber;
        @AuraEnabled public String id; //this refers to ConstantContact List ID.
    }
}

Test Class
 
@isTest 
private class N_ContactImport_TableTest {
    static testMethod void validateN_ContactImport_Table() {
        
        N_ContactImport_Table.Column col = new N_ContactImport_Table.Column();
        col.data = 'data' ; 
        col.type = 'type' ;
        col.title = 'title' ; 
        
        N_ContactImport_Table.ContactWrapper coln = new N_ContactImport_Table.ContactWrapper();
        
        N_ContactImport_Table tab = new N_ContactImport_Table() ;
        tab.columns = new List<N_ContactImport_Table.Column>{col};
            tab.contactWrapperList = new List<N_ContactImport_Table.ContactWrapper>{coln};
                tab.cData = 'Data';
        tab.next_link ='next_link';
        
    }
}

​​​​​​​