You need to sign in to do that
Don't have an account?
Akhil Katkam 5
Test class for the below given code(imp)
Hi Developer Community ,
Can u please write test class for this apex code
Thanks in Advance
Can u please write test class for this apex code
public class RSSFeedUtil { public static List<RSSObject> getGoogleRSSObjects(String theUrl) { List<RSSObject> returnList = new List<RSSObject>(); Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(theUrl); req.setMethod('GET'); HttpResponse res = h.send(req); Dom.Document doc = res.getBodyDocument(); Dom.XMLNode feed = doc.getRootElement(); String namespace = feed.getNamespace(); for(Dom.XMLNode child : feed.getChildElements()) { if(child.getName() == 'entry') { RSSObject returnListItem = new RSSObject( child.getChildElement('title', namespace).getText().unescapeHtml4(), child.getChildElement('link', namespace).getAttribute('href', ''), child.getChildElement('content', namespace).getText().unescapeHtml4(), child.getChildElement('published', namespace).getText() ); System.debug(returnListItem); returnList.add(returnListItem); } System.debug(returnList); } return returnList; } }
Thanks in Advance
For Http Callout first you have to create HttpCalloutMock class in your org then you need to refer that class in Test class.
1. Create the below Mock Apex class in your org:
2. Apex Test class:
Thanks.
Maharajan.C
All Answers
You have to make mockUp data to cover HTTP request test class, to get a fake response.
please follow the below link to create mockup class:-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
Please post the sample response and Endpoint URL so that we can easily help you on the mock and test class.
Thanks,
Maahrajan.C
http related code is being covered , i just need test class from
Dom.Document doc = res.getBodyDocument();
can u please help me test class for red lines that need to be covered
thanks in advance
For Http Callout first you have to create HttpCalloutMock class in your org then you need to refer that class in Test class.
1. Create the below Mock Apex class in your org:
2. Apex Test class:
Thanks.
Maharajan.C
Kolkata FF (https://kolkata-ff.net)
Nagaland State Lottery (https://nagalandstatelotterysambad.com)
brown leather jacket womens (https://glorystore.com.au/product/womens-chocolate-brown-leather-biker-jacket/)
thanks you for a such awesome article.
shearling coat mens (https://glorystore.uk/collections/men-shearling-longcoat)