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
Devadarsi Devasis 9Devadarsi Devasis 9 

Can anyone provide me a simple test class for my apex class?

public with sharing class dsiplaycases {
       @AuraEnabled
       public static Integer TotalRecords(){
           return [Select count() from Case];
       }
    @AuraEnabled(cacheable=true)
       public static List<Case> getCaseList(){
           return [select id, casenumber, subject,acc__c,reason,status,origin,con__c from case WITH SECURITY_ENFORCED ];
       }
       @AuraEnabled(cacheable=true)
       public static List<Case> getCaseList(Integer v_Offset, Integer v_pagesize){
           return [select id, casenumber, subject,acc__c,reason,status,origin,con__c from case limit :v_pagesize OFFSET :v_Offset];
       }

       @AuraEnabled(cacheable=true)
       public static Integer getNext(Integer v_Offset, Integer v_pagesize){
           v_Offset += v_pagesize;
           return v_Offset;
       }

       @AuraEnabled(cacheable=true)
       public static Integer getPrevious(Integer v_Offset, Integer v_pagesize){
           v_Offset -= v_pagesize;
           return v_Offset;
       }
    
}
AnudeepAnudeep (Salesforce Developers) 

Test class for AuraEnabled methods is done in the same way you would test any other code, by executing the method under test. For example:
 
@isTest
private class AuraEnabledTests
{
    @isTest
    static void TestTotalRecords()
    {
        Integer result = dsiplaycases.TotalRecords('test@test.test', 'pass');
        System.assertEquals(null, result);
    }
 @isTest
    static void TestgetCaseList()
    {
        List<Case> result = dsiplaycases.getCaseList();
        System.assertEquals(null, result);
    }
@isTest
    static void TestgetCaseList2()
    {
        List<Case> result = dsiplaycases.getCaseList(2,3);
        System.assertEquals(null, result);
    }
@isTest
    static void TestgetNext()
    {
        List<Case> result = dsiplaycases.getNext(2,3);
        System.assertEquals(null, result);
    }
@isTest
    static void TestgetPrevious()
    {
        List<Case> result = dsiplaycases.getPrevious(2,3);
        System.assertEquals(null, result);
    }
}


If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep
Devadarsi Devasis 9Devadarsi Devasis 9
Hi Anudeep
The code you provided is showing error:
At line 7 its showing: Method does not exist or incorrect signature: void TotalRecords(String, String) from the type dsiplaycases
At line 25 and 32 its showing: Illegal assignment from Integer to List<Case>
Can you please help me out.
AnudeepAnudeep (Salesforce Developers) 
Apologies for the late reply 

Please replace TestTotalRecords() method with the following
 
@isTest
    static void TestTotalRecords()
    {
        Integer result = dsiplaycases.TotalRecords();
        System.assertEquals(null, result);
    }

Let me know if it gives you any coverage