0
@isTest
public with sharing class ContactTriggerHandlerTest {
    @isTest
    public static void afterInsertHandlerTest() {
        List<Account> testAccounts = new List<Account>();
        testAccounts.add(new Account(Name = 'Test 11'));
        testAccounts.add(new Account(Name = 'Test 22'));

        Test.startTest();
        insert testAccounts;
        Test.stopTest();
   }
}

I dont know why im getting a "Methods defined as TestMethod do not support Web service callouts" error when running test.

1 Answer 1

0

When you use Test.startTest() and Test.stopTest();, async code (@future, batchable, queueable, schedulable) is caused to run after Test.stopTest();

So through some path of execution, your account insertion is causing a callout to happen (through some async apex, because callouts can't be made from a trigger context).

Using Test.startTest() and Test.stopTest() is good practice, and you should keep using them. To work around this error, you'll need to implement HttpCalloutMock. See Testing HTTP Callouts for more details on that.

1
  • hi derek thanks for the reply but even if I remove the Test.startTest() and Test.stopTest() im still getting the same error this issue occur when I use a DML statements in Apex Testing.
    – SFNewbie
    Commented Nov 7, 2022 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .