+ Start a Discussion

Prepare (create) data before testing callouts

My class which perform a callout reads sObject by it's Id and then perform callout with data from this object.

For testing callouts I've created mock using

global class Some_Test implements HttpCalloutMock {
	global HTTPResponse respond(HTTPRequest req) {
    	HttpResponse response = null;
response = new HttpResponse(); // set needed information response.setBody('some body goes here'); response.setHeader('Content-Length', response.getBody().length().format()); response.setStatusCode(200); //...
return response; } static { // Set mock callout class Test.setMock(HttpCalloutMock.class, new ATT_WS_Worker_Test()); } public ATT_WS_Worker_Test() { Account account1 = new Account(Name='Account_1'); insert account1; } Account account1 = null; @isTest static void composingRequestTest() { Test.startTest(); // make a callout using account1's Id Test.stopTest(); } }

 As you may understand it will tell me that I'm wrong and I can't perform insert/update before callouts.



Is there a way to prepare/create data before testing callouts?