I'm trying here to write a test class for below apex class, I'm getting the below error when in the compilation:
Methods defined as TestMethod do not support Web service callouts
Test class:
@isTest
Public class testPricingSalesforceController{
@isTest static void testCallout() {
// Call method to test.
// This causes a fake response to be sent
//Test.setMock(PricingSalesforceController.class, new testPricingSalesforceController());
//Test.setMock(HttpCalloutMock.class, new YourHttpCalloutMockImpl());
// from the class that implements HttpCalloutMock.
String res = PricingSalesforceController.reqprice('CM','NSA','222Y16C',2);
//return res();
// Verify response received contains fake values
//System.assertEquals('Mock response', res);
// res=getbody();
}
}
Apex class
Public class PricingSalesforceController {
@AuraEnabled
public static string reqprice(string famil,string idcom,string partno,integer qty){
HttpRequest req = new HttpRequest();
req.setEndpoint('https://www.goodmsl.com/sdsadd_/price.php?famille='+famil+'&idcompte='+idcom+'&ref='+partno+'&qt='+qty);
req.setMethod('GET');
// Specify the required user name and password to access the endpoint
// As well as the header and header information
String username = '000dwe000';
String password = '0000%';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
// Create a new http object to send the request object
// A response object is generated as a result of the request
System.debug(req);
Http http = new Http();
HTTPResponse res = http.send(req);
// String mapString = (res.getbody()).tostring();
System.debug(res.getbody());
// system.debug(mapString);
return res.getbody();
//Map < String,
//Object > resultsMap = (Map < String, Object > ) JSON.deserializeUntyped(res.getBody());
// system.debug('resultsMap-->' + resultsMap);
//return resultsMap;
}
}
Test.isRunningTest()