function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EnryEnry 

TestMethod do not support Web service callouts, test skipped

Hi ,

I have written a test class for a trigger on the lead object.

When i run the test class i get the following error:

 

Methods defined as TestMethod do not support Web service callouts, test skipped

 

There is an other trigger on lead that has a call to a webservice so i get this error.

I have wrapped the call with:

 

if (!Test.isRunningTest())
{
   // do callout
}

 

 But i’m still getting the same error.

Any other way to run correctly the test class?

Thank you in advantage.

BR.

 

Avidev9Avidev9
Probably its being called by some other method/event. Have a close look it should work.

Anyways you can give a try to HttpCalloutMock interface for testing, more precisely real unit testing.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm
EnryEnry

Thank you very much for you reply.

Pleace Can you explain in more detail your solution.

I don't know anything about HttpCallout.

 

This is my test class:

@isTest(seeAllData=true)
private class TestsetOwner {

static testMethod void TestsetOwner() {

       //CREATE A GROUP AND A QUEUE
      //  Group g1 = new Group(Name='group name', type='Queue');
        //        insert g1;
          //      QueuesObject q1 = new QueueSObject(QueueID = g1.id, SobjectType = 'Lead');
          // insert q1;
           
           
        // CREATE A USER
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
         User u2 =new User( Alias = 'newUser1' ,
                            Email ='newuser123@testorg.com',
                            EmailEncodingKey = 'UTF-8',
                            LastName = 'Testing',
                            LanguageLocaleKey='en_US',
                            LocaleSidKey='en_US', 
                            UserName='newuser123@testorg.com',
                            ProfileId=p.Id,
                            TimeZoneSidKey    = 'America/Los_Angeles');
         insert u2;
         
         
        // GET QUEUE ID
         QueueSobject q=new QueueSobject();
        q =[Select Queue.Id,Queue.Name from QueueSobject where Queue.Name='ArchivedLeads' LIMIT 1];      
          
         // q.Queue.Id='00GM0000000dkqQ';
           //CREATE A LEAD 1
                 
                    Lead lead = new Lead();
                    Lead.OwnerId = q.Queue.Id;
                    lead.LastName = 'last';
                    lead.FirstName = 'First';
                    lead.Company = 'Company';
                    lead.Status = 'NewStatus';
                    lead.IsUnreadByOwner = True;
                    lead.Archived_Original_Owner__c=u2.Id;
                    lead.Country='Sweden';
                    lead.Email='shshdkjd@fkfk.fi';
                    lead.Phone='3333';
                    lead.MobilePhone='3333';
                    lead.Switchboard__c='3333';
                   
                    insert lead;
                    
                     //CREATE A LEAD 2
                     Lead lead2 = new Lead();
                     Lead2.OwnerId = u2.Id;
                    lead2.LastName = 'last';
                    lead2.FirstName = 'First';
                    lead2.Company = 'Company';
                    lead2.Status = 'NewStatus';
                    lead2.IsUnreadByOwner = True;
                    lead2.Country='Sweden';
                    lead2.Email='shshdkjd@fjfjf.fi';
                    lead2.Phone='3333';
                    lead2.MobilePhone='3333';
                    lead2.Switchboard__c='3333';
                    insert lead2;
                    
            test.startTest();

        lead.Status = 'Unqualified';
        update lead;

       // Lead lTest = [SELECT Id, status FROM Lead WHERE Id=:lead.Id];
        
        //system.assertEquals(false, lTest.status);
        
        lead2.Status = 'false';
        // SET LEAD OWNER = QUEUE
       // lead2.OwnerId=q.Queue.Id;
       
        
        update lead2;
        
         lead.Status = 'false';
        lead.OwnerId=lead.Archived_Original_Owner__c;
        update lead;       
        

    test.stopTest();
}
}

 

 

What code should i insert to give a HttpCalloutMock interface to the test class?

Thanks.

Avidev9Avidev9
Well I will suggest you to have a look @ the webservice.
Make sure there are only one webservice.

My Suggestion : Look for other triggers and check whether they have webservice calls associated with them.

I can't tell you about the webservice call by having a look at the test class
EnryEnry

Thank you again!

I don't find other triggers on lead with a call to a webservice.

I think that there are other classes that have calls.

 

Do yo think is a good solution to find all the calls(in classes and triggers) to the webservice and wrapper them?

Avidev9Avidev9
well can you tell me how are you running the test class?
If you are running a single test class(this one) at a time and it still gives you an error, it means that there is another trigger which is having the callout
EnryEnry

Yes, i'm running just my test class(from select test).

I looked at the code for all triggers on lead but nothing.

I'm looking also in the debug log but i am not able to find what other trigger is executed.

Avidev9Avidev9
Can you put your class/trigger which has the webservice callout
EnryEnry

I deleted the trigger because it was old and no longer needed.

But i'm still getting the error.

I have another call in an trigger on user object;in the log i see that there is a call from this trigger. 

But i don't understand why i'm executing also a trigger on user.

have i to wrapper also the call that there aren't make from triggers on lead?

 

Avidev9Avidev9

If you have a close look at your test class you will find that it is doing DML @User object

 

User u2 =new User( Alias = 'newUser1' ,
                            Email ='newuser123@testorg.com',
                            EmailEncodingKey = 'UTF-8',
                            LastName = 'Testing',
                            LanguageLocaleKey='en_US',
                            LocaleSidKey='en_US', 
                            UserName='newuser123@testorg.com',
                            ProfileId=p.Id,
                            TimeZoneSidKey    = 'America/Los_Angeles');
         insert u2;
         

 You should be following the best practices for test method and write test classes accordingly like wrapping httpmock etc.