You need to sign in to do that
Don't have an account?

Technical concept of HttpCalloutMock.class
Hi All,
Test.setMock(HttpCalloutMock.class, new AnimalsHttpCalloutMock());
Please let me know the technical understanding of the HttpCalloutMock.class? I guess, it is interface.class / class.class. Where could we use the class.class or interface.class?
Test.setMock(HttpCalloutMock.class, new AnimalsHttpCalloutMock());
Please let me know the technical understanding of the HttpCalloutMock.class? I guess, it is interface.class / class.class. Where could we use the class.class or interface.class?
Hi Anshul,
go to referal url :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
as suraj mentioned that's is the right.
and AnimalResult result = (AnimalResult) JSON.deserialize(response.getBody(), AnimalResult.class).
AnimalResult is the another class such as wrapper class , in where you are doing set response body.
for instance :
let me know if it helps you and marking it as best answerpublic class AnimalResult{
public string sResponse;
public string sData;
}
assume that you have a class in where you have 2 property like above when you execute following line the response data automaticly store into animalResult's property.
AnimalResult result = (AnimalResult) JSON.deserialize(response.getBody(), AnimalResult.class).
but make sure that the property name must be into impletemantion class's body.
for example following is your implement class and your property name must be into this class response body like following.
res.setBody('{"example":"test",
"sResponse" : "putValue",
"sData": "putData"}');
Thank you
All Answers
what does it mean by AnimalResult.class?
Greetings!
Test.setMock is used to create a fake response.
It helps you to cover your code coverage in Test class.
In Another statement AnimalResult result = (AnimalResult) JSON.deserialize(response.getBody(), AnimalResult.class).,
In which, we parse our JSON Data into AnimalResult class instance.
Which we can insert or update in the apex.
Please mark it as the best answer if it helps you to fix the issue.
Thank you!
Regards,
Suraj Tripathi
I understand the Test.setMock is used to create a fake response. Could you explain the technical concept AnimalResult.class OR HttpCalloutMock.class. AnimalResult is the class, HttpCalloutMock is the interface.
Hi Anshul,
go to referal url :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
as suraj mentioned that's is the right.
and AnimalResult result = (AnimalResult) JSON.deserialize(response.getBody(), AnimalResult.class).
AnimalResult is the another class such as wrapper class , in where you are doing set response body.
for instance :
let me know if it helps you and marking it as best answerpublic class AnimalResult{
public string sResponse;
public string sData;
}
assume that you have a class in where you have 2 property like above when you execute following line the response data automaticly store into animalResult's property.
AnimalResult result = (AnimalResult) JSON.deserialize(response.getBody(), AnimalResult.class).
but make sure that the property name must be into impletemantion class's body.
for example following is your implement class and your property name must be into this class response body like following.
res.setBody('{"example":"test",
"sResponse" : "putValue",
"sData": "putData"}');
Thank you