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
sunny@99-chgsunny@99-chg 

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

trigger Miles on Quote (before insert,before update) {
for(Quote q:trigger.new){
opportunity opp=[select id,Distance_in_Miles__c from opportunity where id=:q.opportunityid limit 1];
q.Delivery_Miles__c=opp.Distance_in_Miles__c;
q.Amount_of_Truck__c=q.Square_Feet_quote__c/10000;
}
}

 

for the above trigger i wrote a test class like this....but this test class is not covering a trigger...

its showing an error like    "Methods defined as TestMethod do not support Web service callouts, test skipped ".....

please solve this problem....

 

@isTest
public class testquote
{
        public static testMethod void QuotetTest()
        {
        account a=new account(name='icc',type='new client',industry='church',phone='9985354198');
        insert a;
        opportunity opp=new opportunity(name='test',Lost_to__c='big top',Distance_in_Miles__c=200.20,StageName='Closed Won',closedate=system.today()+2,leadsource='website',type='rental-new client',address1__c='blr',address2__c='hyd',Application__c='aviation',Budgeted_Cost__c=2500.20,City1__c='las vegas',Divsion__c='builtsure',Country1__c='usa');
                                          
        insert opp;
        
        quote q=new quote(name='test',Due_With_Signed_Agreement__c=30.20,Opportunityid =opp.id,Length_in_Meters__c=20,Title_of_Quote__c='this is shipping',TFS_Type_by_Width__c='20',Due_Prior_to_Shipping__c=20.20,delivery_miles__c=150.20,Amount_of_Truck__c=2000,Amount_Per_Mile__c=20.50,Due_After_Install__c=20,Start_Date__c=system.now().date());
                           
        insert q;
        system.debug(q.delivery_miles__c+'@@@@');
        update opp;
     
       
        update q;

        }

}

 

 

// please solve this......

Praveen_K.ax1208Praveen_K.ax1208

A SOQL query can not be run by using a test class. use if(test.isrunningtest()) condition to skip the SOQL query and assign the values from test class manually to cover the code.

Hope it works...

Please try this and let me know if it works..

 

Thanks,

Praveen K.

SForceBeWithYouSForceBeWithYou

Please, use this in your test method and all will be resolved....

 

StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
mock.setStaticResource('NameOfStaticResourceContainingResponseBodyString');
mock.setStatusCode(200); // Or other appropriate HTTP status code
mock.setHeader('Content-Type', 'application/json'); // Or other appropriate MIME type like application/xml
Test.setMock(HttpCalloutMock.class, mock);

 Here is the link to the implementation this uses:

http://www.salesforce.com/us/developer/docs/apexcode/index.htm

 

Here is the section that covers this in general:

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

 

May The SForce Be With You!

 

Nathan Pepper

youtube.com/MayTheSForceBWithYou

@SForceBeWithYou