0

I tried so much time to get the code coverage of my class more then 75% but i am getting error (like this : Methods defined as TestMethod do not support Web service callouts, test skipped) in production organization.

The same class and same test class i have wrote in sandbox and it was working fine and get me 93% code coverage but when i am doing this same process in production i am getting error (Methods defined as TestMethod do not support Web service callouts, test skipped).

so what is the reason behind this ?

@isTest
Public class GenereatControllerTest{

static testMethod void test(){

    Test.isRunningTest();

    Account acc=new Account();
    acc.Name='test';
    insert acc;

    Vendor_Order__c vo=new Vendor_Order__c();
    vo.Vendor__c=acc.id;
    insert vo;

    Attachment atta = new Attachment();
    atta.Body=Blob.valueOf('ww');
    atta.Name=vo.Name+' '+Date.today().year()+Date.today().month()+Date.today().day()+'_V'+(1)+'.pdf';  
    atta.ParentId=vo.Id;
    insert atta;

    Document doc=new Document();
    doc.Name=atta.Name;
    doc.FolderId=userinfo.getUserId();
    doc.Body=atta.Body;
    insert doc;

    PageReference pc = new PageReference('/apex/GenerateController?typ=send&id='+vo.id);
    Test.setCurrentPage(pc);

    GenerateController p = new GenerateController();
    p.id=vo.Id;
    p.getId();    
    p.init();
    ApexPages.currentPage().getParameters().put('typ','save');
    p = new GenerateController();
    p.id=vo.Id;
    p.getId();    
    p.init();
}

}

7
  • If you are firing a callout in a test class, this error will come . You need to implement a mock. Can you post your test class ? Commented Jul 20, 2015 at 10:19
  • Please see my edited question for test class code
    – Nihar
    Commented Jul 20, 2015 at 10:22
  • Do you have a callout in any of the method of corresponding controller ? May be using Webservice methods or http request? Commented Jul 20, 2015 at 10:24
  • No. I am not using any kind of http request or Webservice methods.
    – Nihar
    Commented Jul 20, 2015 at 10:29
  • Check my answer. probably it will give you a way out. Commented Jul 20, 2015 at 10:33

2 Answers 2

1

I strongly believe this has to do with getContent() and getContentAsPDF() method. This was a critical update from salesforce which seems to be activiated in your production and not in sandbox so test class work fine in sandbox but not in production. This update basically considers the above two methods as callouts as opposed to regular method before. So the only solution I can think of is try implementing a Mock as opposed to these methods or just apply check of

if(!test.isrunningtest())

to ensure that these methods are called only in regular context and not in context of test class.

enter image description here

5
  • So, You mean i have to set that condition in test class like below : @isTest Public class GenereatControllerTest{ if(!test.isrunningtest()){ // My test class code } }
    – Nihar
    Commented Jul 20, 2015 at 10:44
  • First of all are you using any of these 2 methods i highlighted? Commented Jul 20, 2015 at 10:45
  • Yes. I am using getContentAsPDF()
    – Nihar
    Commented Jul 20, 2015 at 10:45
  • So now you CANNOT directly call that method in your test class context. You will have to either implement a mock or apply the check in original class (not test class) as I mentioned in my Answer above. If you need more inputs please post your method too. Commented Jul 20, 2015 at 10:53
  • Amit I have done. Thank you so much for your great valuable time and Answer.
    – Nihar
    Commented Jul 20, 2015 at 11:17
1

you may want to include test.isrunningtest in your actual callout class to check you are not going to run actual callout and only test mock. take a look on this thread

Testing HttpCallout with HttpCalloutMock and UnitTest Created Data

2

You must log in to answer this question.

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