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
Deepak Sharma 184Deepak Sharma 184 

Test Class for Html file in static resource

Hi,

I have stored the html page in static resource and showing it via lightning component. how to cover the static resource test class?

Apex code - 
@auraEnabled
public static string getFooterContent(String staticResourceName) {
   
    Blob bodydata =  [SELECT Body FROM  StaticResource  WHERE Name = :staticResourceName].Body;
    String s = bodydata.toString();
    
    return s;
}
Best Answer chosen by Deepak Sharma 184
CharuDuttCharuDutt

Hii Deepak 
We Cannot Create Static Resource In Apex
So We Have Just Call The Methos From Test Class And pass The Static Resource Name Availiable in Your Org

@isTest
public class StaticResourceTest {
@isTest
    public Static Void UnitTest(){
        StaticResource.getFooterContent('Static Resource Name Availiable in Your Org');
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Deepak
Try Below Test Class
@isTest
public class StaticResourceTest {
@isTest
    public Static Void UnitTest(){
        StaticResource.getFooterContent('AudioLogo');
    }
}
Please Mark It As Best Answer If It Helps
Thank You!
Deepak Sharma 184Deepak Sharma 184
Hi CHaru,
Thanks for your reply.

I think we need to insert the static resource html file, before calling the method.
its giving the List has no rows for assignment to SObject.


Regards,
Deepak
CharuDuttCharuDutt

Hii Deepak 
We Cannot Create Static Resource In Apex
So We Have Just Call The Methos From Test Class And pass The Static Resource Name Availiable in Your Org

@isTest
public class StaticResourceTest {
@isTest
    public Static Void UnitTest(){
        StaticResource.getFooterContent('Static Resource Name Availiable in Your Org');
    }
}
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
Deepak Sharma 184Deepak Sharma 184
Okay!
Thanks for your help! Charu