You need to sign in to do that
Don't have an account?
Static Resource Mock - Help Needed
Hello I want to use a static resource for my Mock but I cannot get it to work where am I going wrong based on this snippet of code:
I have no doubt it is to do with the res vs the mock but I cannot work out the issue
@isTest global class TrelloAPICalloutClass_Mock implements HttpCalloutMock { public static HttpResponse res; public static HttpRequest req; private String whichMock; public TrelloAPICalloutClass_Mock (String mockNeeded){ this.whichMock = mockNeeded; } global HTTPResponse respond(HTTPRequest req){ res = new HttpResponse(); switch on whichMock { when 'createboards' { createBoardMock(); } when 'getattachment' { attachmentMock(); } when 'gettrelloboards' { getTrelloBoardsMock(); } when 'getTrelloListsFromBoardMock' { getTrelloListsFromBoardMock(); } when 'getTrelloLabelsFromBoardsMock' { getTrelloLabelsFromBoardsMock(); } when 'getTrelloBoardsMockError' { getTrelloBoardsMockError(); } when 'getTrelloBoardsMockNewBoard' { getTrelloBoardsMockNewBoard(); } when 'getTrelloBoardsMockUpdateName' { getTrelloBoardsMockUpdateName(); } when 'getTrelloListsFromBoardMockNewList' { getTrelloListsFromBoardMockNewList(); } } return res; } private static void getTrelloBoardsMock(){ // Get The Trello Boards StaticResourceCalloutMock mock = new StaticResourceCalloutMock(); mock.setStaticResource('getOrgBoards'); mock.setHeader('Content-Type', 'application/json'); mock.setStatusCode(200); Test.setMock(HttpCalloutMock.class, mock); }
I have no doubt it is to do with the res vs the mock but I cannot work out the issue
All Answers
Thank you for sharing the fix. Can you elaborate more/provide code on the way you call the method in the test.