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
SalesforceAddictSalesforceAddict 

anyone can write test class for this apex class

public class fetchPicklistOptsController {    
    
    /*fetch USser Name*/
    @AuraEnabled 
    public static user fetchUser(){
        User u = [select id,Name from User where id =: userInfo.getUserId()];
        return u;
    }
}
Best Answer chosen by SalesforceAddict
Raj VakatiRaj Vakati
try this
 
@isTest
private class TestfetchPicklistOptsController {

   static testMethod void testCase1() {
	   
	    Profile pf= [Select Id from profile where Name='System Administrator']; 
        
        String orgId=UserInfo.getOrganizationId(); 
        String dateString=String.valueof(Datetime.now()).replace(' ','').replace(':','').replace('-','') ;
        Integer RandomId=Integer.valueOf(Math.rint(Math.random()*1000000)); 
        String uniqueName=orgId+dateString+RandomId; 
        User uu=new User(firstname = 'ABC', 
                         lastName = 'XYZ', 
                         email = uniqueName + '@test' + orgId + '.org', 
                         Username = uniqueName + '@test' + orgId + '.org', 
                         EmailEncodingKey = 'ISO-8859-1', 
                         Alias = uniqueName.substring(18, 23), 
                         TimeZoneSidKey = 'America/Los_Angeles', 
                         LocaleSidKey = 'en_US', 
                         LanguageLocaleKey = 'en_US', 
                         ProfileId = pf.Id
                        ); 
        
        
        insert uu;
		System.runAs(uu){
		fetchPicklistOptsController.fetchUser();
		}
       
    }
}