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
sfdc@isha.ax1814sfdc@isha.ax1814 

Lightningcomponent Apexclass testclass - Urgent help

Hi Team,

I need help on testclass for below lightning componnet apex class.
Can anyone help me on this .


public class LightningTabComponentController {
/* Method to fetch the parameters used for framing the URL*/ 
    
   @AuraEnabled
    public static OpptyRelatedData getCustomsettingValue()
    {
       OpptyRelatedData returnrelateddata = new  OpptyRelatedData ();
        
       string cusseturl= SMX_URL__c.getInstance().SMX_URL__c;
       returnrelateddata.SMX = cusseturl;
        
       string cusseturl1 = SFDC_URL__c.getInstance().SFDC_URL__c;
       returnrelateddata.SFDCURL = cusseturl1;
        
       String username = UserInfo.getUsername();
       returnrelateddata.username=username;
        
       String sessionId = UserInfo.getsessionId();
       returnrelateddata.sessionId=sessionId;
        
        
       String npxaccview = SFDC_URL__c.getInstance().NPX_Account_View_Embed__c;
       returnrelateddata.npxaccview=npxaccview;
        
        String npxconview = SFDC_URL__c.getInstance().NPX_Contact_View_Embed__c;
       returnrelateddata.npxconview=npxconview;
        
         string urler = URL.getSalesforceBaseUrl().toExternalForm();
        returnrelateddata.urler=urler;
           
       system.debug('returnrelateddatareturn======>'+returnrelateddata); 
       return returnrelateddata;
    }
    
    public class OpptyRelatedData{
        @AuraEnabled 
        Public string SMX{get;set;}
        @auraEnabled
        public string SFDCURL{get;set;}
        @auraEnabled
        public string username{get;set;}
        @auraEnabled
        public string sessionId{get;set;}
        @auraEnabled
        public string npxaccview{get;set;}
        @auraEnabled
        public string npxconview{get;set;}
        @auraEnabled
        public string urler{get;set;}
        
        
    } 
    
}


Regards,
Isha
Deepali KulshresthaDeepali Kulshrestha
Hi,

Greetings to you!

Use the following code. It may helpful for you
 
@isTest
public class TestLightingTabComponentController {
    
    @isTest() 
    static void testLightningTabComponentMethod(){
        String SMX='test';
        System.assertEquals(SMX, 'test');
        
        String SFDCURL='https://www.techopedia.com/definition/1352/uniform-resource-locator-url';
        System.assertEquals(SFDCURL, 'https://www.techopedia.com/definition/1352/uniform-resource-locator-url');
        
        String username='Venom';
        System.assertEquals(username, 'Venom');
        
        String sessionId='teyy@121';
        System.assertEquals(sessionId, 'teyy@121');
        
        String npxaccview='Account';
        System.assertEquals(npxaccview, 'Account');
        
        String npxconview='Contact';
        System.assertEquals(npxconview, 'Contact');
        
        String urler='test';
        System.assertEquals(urler, 'test');
        
        Test.StartTest();  
        LightningTabComponentController.getCustomsettingValue();
        Test.StopTest(); 
    }       
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com