You need to sign in to do that
Don't have an account?
Sandeep TechAffinity
How to cover else part in Mock Test class?
Hi Guys,
I wrote a test class for Mock Test which covers when if the status code is 200, now I want to cover else part which is other than 200.
I wrote a test class for Mock Test which covers when if the status code is 200, now I want to cover else part which is other than 200.
@isTest public class ChatMessageTrigger_Test { private class RestMock implements HttpCalloutMock { public HTTPResponse respond(HTTPRequest req) { String fullJson = '{data={"Event":"ChatMessageRecieved","Timestamp":"2021-10-26 06:40:10","attemptNumber":1,"ChatThread":{"ChatThreadId":"1537903","WithNumber":"+14074610978","DateCreated":"2021-10-05 06:47:02"},"}]}}'; HTTPResponse res = new HTTPResponse(); res.setHeader('Content-Type', 'text/json'); res.setBody(fullJson); res.setStatusCode(200); return res; } } }
Kindly refer this guide for the Mock test class :-
https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock
Thanks!