You need to sign in to do that
Don't have an account?
John McAfee
testclass fails at incert Case with TestMethod do not support Web service callouts
Test class below that was working perfectly is now failing with "Methods defined as TestMethod do not support Web service callouts" I have narrowed it down to the case insert line insert c; . Is this a permissions issue on the case object ? all the other inserts work .
@isTest
public class DefaultEntitlementTest {
static testmethod void ValidateDefaultEntitlementAction() {
Account[] acc = new Account[] {
new Account(Name='Test Account 1'),
new Account(Name='Test Account 2')
};
insert acc;
Contact[] contacts = new Contact[] {
new Contact(FirstName='Test 1', LastName='McTesty', AccountId = acc[0].id),
new Contact(FirstName='Test 2', LastName='McTesty', AccountId = acc[0].id)
};
insert contacts;
Id entitlementProcessId = [SELECT Id FROM SlaProcess WHERE SObjectType = 'Case' LIMIT 1].Id;
Entitlement[] ent = new Entitlement[] {
new Entitlement (AccountId=acc[0].Id, SLAProcessId = entitlementProcessId, Name = 'Test Entitlement Account',
StartDate = system.today(), EndDate = system.today()),
new Entitlement (AccountId=acc[1].id, SLAProcessId = entitlementProcessId, Name = 'Test Entitlement Contact',
StartDate = system.today().addDays(-1), EndDate = system.today().addDays(5))
};
insert ent;
EntitlementContact ec = new EntitlementContact(ContactId = contacts[0].id, EntitlementId = ent[1].id);
insert ec;
Case c = new Case(AccountId = acc[0].id, ContactId = contacts[0].id, Subject='Test');
insert c;
List<Case> caseList = new List<Case>{c};
DefaultEntitlementAction.updateDefaultEntitlements(caseList);
}
}
@isTest
public class DefaultEntitlementTest {
static testmethod void ValidateDefaultEntitlementAction() {
Account[] acc = new Account[] {
new Account(Name='Test Account 1'),
new Account(Name='Test Account 2')
};
insert acc;
Contact[] contacts = new Contact[] {
new Contact(FirstName='Test 1', LastName='McTesty', AccountId = acc[0].id),
new Contact(FirstName='Test 2', LastName='McTesty', AccountId = acc[0].id)
};
insert contacts;
Id entitlementProcessId = [SELECT Id FROM SlaProcess WHERE SObjectType = 'Case' LIMIT 1].Id;
Entitlement[] ent = new Entitlement[] {
new Entitlement (AccountId=acc[0].Id, SLAProcessId = entitlementProcessId, Name = 'Test Entitlement Account',
StartDate = system.today(), EndDate = system.today()),
new Entitlement (AccountId=acc[1].id, SLAProcessId = entitlementProcessId, Name = 'Test Entitlement Contact',
StartDate = system.today().addDays(-1), EndDate = system.today().addDays(5))
};
insert ent;
EntitlementContact ec = new EntitlementContact(ContactId = contacts[0].id, EntitlementId = ent[1].id);
insert ec;
Case c = new Case(AccountId = acc[0].id, ContactId = contacts[0].id, Subject='Test');
insert c;
List<Case> caseList = new List<Case>{c};
DefaultEntitlementAction.updateDefaultEntitlements(caseList);
}
}
Do you have a new code that is making http callout? That is impacting your existing test class, you need to update the Test class to make it work.
Here is the link for you reference
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
All Answers
Do you have a new code that is making http callout? That is impacting your existing test class, you need to update the Test class to make it work.
Here is the link for you reference
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
Test.setMock(HttpCalloutMock.class, new TestMockService());
//Mockup service
private class TestMockService implements HttpCalloutMock {
public HTTPResponse respond(HTTPRequest req) {
String response;
HTTPResponse res = new HTTPResponse();
res.setStatusCode(200);
return res;
}
}
So was my response helpful. Please mark it best if it was?
Just following up to see if I was being helpful on this.