+ Start a Discussion
Eric TeseurEric Teseur 

Create test for class

Hello, I have a class and I need write a test
Here is my code:

public with sharing class arcListClass {

 @AuraEnabled
 public static void saveInput(List < DerexSoft__c > ListDerexSoft) {
  Insert ListDerexSoft;
 }
 @AuraEnabled
 public List < DerexSoft__c > arcList = new List < DerexSoft__c > ();

 @AuraEnabled
 public List < DerexSoft__c > softrec = new List < DerexSoft__c > ();

    @AuraEnabled
 public List < DerexSoft__c > dectrec = new List < DerexSoft__c > ();    

 @AuraEnabled(cacheable = true)
 public static List < DerexSoft__c > getArray(String query) {
  arcListClass alc = new arcListClass();
  alc.arcList = Database.query('SELECT Id, Uforted__c, Softed__c, Context__c,  LastModifiedDate FROM DerexSoft__c ORDER BY Context__c asc LIMIT 1');
  return alc.arcList;
 }
 @AuraEnabled
 public static List < DerexSoft__c > delSlctRec(List < String > slctRec) {
  arcListClass alc = new arcListClass();
  alc.dectrec = [SELECT Id FROM DerexSoft__c WHERE Id IN: slctRec];
  try {
   delete alc.dectrec;
  } catch (Exception ex) {
   throw new AuraHandledException(ex.getMessage());
  }
  alc.arcList = Database.query('SELECT Id, Uforted__c, Softed__c, Context__c, LastModifiedDate FROM DerexSoft__c LIMIT 1');

  return alc.arcList;

 }
 @AuraEnabled
 public static List < DerexSoft__c > sortSlctRec(List < String > slctRec) {
    // Integer integerExamp = 0;
  List < DerexSoft__c > softrec = new List < DerexSoft__c > ();
  arcListClass alc = new arcListClass();
 List <DerexSoft__c> sortApRec = [SELECT Id, Uforted__c, Softed__c,  Context__c FROM DerexSoft__c WHERE Id IN: slctRec];
  try {
   
        for(DerexSoft__c sortobj : sortApRec){
            String sortString = sortobj.Uforted__c;
            List<String> sortList = sortString.split(',');
            List<Integer> intList = new List<Integer>();
            for(String s : sortList){
                intList.add(Integer.valueOf(s));
            }
            Integer compl  = QuickSort.sort(intList); 
            sortString = string.join(intList,'.'); // pass  .\,\;
            sortobj.Softed__c = sortString;
            sortobj.Context__c = compl;
            softrec.add(sortobj);
            
        }    
        update softrec;  
        softrec.clear();  

  } catch (Exception ex) {
   throw new AuraHandledException(ex.getMessage());
  }
  alc.arcList = Database.query('SELECT Id, Uforted__c, Softed__c, Context__c,  LastModifiedDate FROM DerexSoft__c ORDER BY Context__c LIMIT 1');
  return alc.arcList;

 }
    
    
}
Alain CabonAlain Cabon
@Eric Teseur

You just need to call all the methods of the class after the creations of several list of DerexSoft__c (easy here) with some assertions.

 List < DerexSoft__c >  mylist = new  List < DerexSoft__c >();
 mylist.add(  new DerexSoft__c  (... some values ...) );
 arcListClass.saveInput ( mylist );
 List < DerexSoft__c >  result1 = arcListClass.getArray ( .... );
 List < DerexSoft__c >  result2 = arcListClass.delSlctRec ( .... );
 ...

By the way, don't use "String query" as a parameter for getArray() ( never used )