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
Shruti NigamShruti Nigam 

Hi all,I want to write test class for the following apex class .Can anyone please help me out with it..??

Here is the apex class for which I want to write test class:-
public class TestController {
    /**
     * Returns JSON of list of ResultWrapper to Lex Components
     * @object - Name of SObject
     * @API_Text - API name of field to display to user while searching
     * @API_Val - API name of field to be returned by Lookup COmponent
     * @limit  - Total number of record to be returned
     * @API_Search - API name of field to be searched
     * @search - text to be searched
     * */
    @AuraEnabled(cacheable=true) 
    public static String searchDatabase(String object, String API_Text, String API_Val, 
                                  Integer limit,String API_Search,String search ){
        
        search='\'%' + String.escapeSingleQuotes(searchText.trim()) + '%\'';

        
        String query1 = 'SELECT '+API_Text+//' ,'+API_Val+
                        ' FROM '+object+
                            ' WHERE '+API_Search+' LIKE '+search+ 
                        ' LIMIT '+limit;
        
        List<sObject> sobjList1 = Database.query(query1);
        List<ResponseWrapper> ret = new List<ResponseWrapper>();
        
        for(SObject s : sobjList){
            ResponseWrapper obj = new ResponseWrapper();
            obj.objName = object;
            obj.text = String.valueOf(s.get(API_Text)) ;
            obj.val = String.valueOf(s.get(API_Text))  ;
            ret.add(obj);
        } 
         return JSON.serialize(ret) ;
    }