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
Sandeep TechAffinitySandeep 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.
 
@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;
        }
    }
}

 
PriyaPriya (Salesforce Developers) 
Hi Sandeep,

Kindly refer this guide for the Mock test class :- 
https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock

Thanks!