0

I have a Batch class:

global class updateCusotmerMasterData implements Database.Batchable<sObject>, Database.Stateful,Database.AllowsCallouts
{
    public updateCusotmerMasterData(){}
    global Database.QueryLocator start(Database.BatchableContext BC)
    {   
        return Database.getQueryLocator([Select id,iCustomer__c  from account where ID NOT IN (Select Account__c from DetailSet__c)]);
        //return Database.getQueryLocator([select id,iCustomer__c from Account where Icustomer__c ='00BE01 Approval UAT10']);
    }
    global void execute(Database.BatchableContext BC,List<Account> Acc)
    {
        list<String> Icustomer = new list<string>();
        for(account Acc1 : Acc)
        {
            Icustomer.add(Acc1.iCustomer__c);
        }
        HTTPSclass.HTTPSclass1(Icustomer);
    }
    global void finish(Database.BatchableContext BC){
    }
}

Test Class:

@isTest

public class TestupdateCusotmerMasterData 
{
    static testmethod void test()
    {
        list<Account> TestAcc = new list<Account>();
        for (Integer i=0;i<10;i++) 
        {
            account acc = new account();
            acc.Name='account'+i;
            acc.iCustomer__c = 'aaa'+i;
            acc.PG_JnJCustomerCode__c='aaa'+i;
            acc.PG_AccountGuid__c='aaa'+i;
            TestAcc.add(acc);
        }
        insert TestAcc; 
        Test.startTest();
        updateCusotmerMasterData UpdateCustomer = new updateCusotmerMasterData();
        Database.executeBatch(UpdateCustomer);
        Test.stopTest();
    }
}

While Running Test Class it is showing error like: Methods defined as TestMethod do not support Web service callouts How to Rectify the error Guide me for the Answer

0

As the error suggests, you cannot do webservice callouts in a test method. In order to test those webservice callouts, you need to utilise HttpCalloutMock. You can refer to this page for reference: https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock.html

| improve this answer | |
  • There is all kinds of sample code. Do some legwork and search for it. It's easy to find even in the link provided. – Eric Nov 21 '16 at 7:23
  • Follow the link or do a search of your own. It's in the docs... – Eric Nov 21 '16 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.