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
nellymnjnellymnj 

TestMethod do not support service callouts

Hello,
I've written S-control that calls external web service. It works on development site, but I could not deploy it on production site. For s-control to work I've generated classes from the external web service wsdl, and written TestMethods for these classes (got 83% test coverage),

the error is : Methods defined as TestMethods do not support Web service callouts, test skipped

//Generated by wsdl2apex

global class localhostSoap {

public class Root_PortType {

public String endpoint_x = 'http://localhost/soap/';

private String[] ns_map_type_info = new String[]{'http://localhost/soap/types', 'localhostSoapTypes', 'http://localhost/soap/', 'localhostSoap'};

public Integer deleteTable(String server_name,Integer port,String table_name) {

localhostSoapTypes.deleteTable_element request_x = new localhostSoapTypes.deleteTable_element();

localhostSoapTypes.deleteTableResponse_element response_x;

request_x.server_name = server_name;

request_x.port = port;

request_x.table_name = table_name;

Map<String, localhostSoapTypes.deleteTableResponse_element> response_map_x = new Map<String, localhostSoapTypes.deleteTableResponse_element>();

response_map_x.put('response_x', response_x);

WebServiceCallout.invoke(

this,

request_x,

response_map_x,

new String[]{endpoint_x,

'deleteTable',

'http://localhost/soap/types',

'deleteTable',

'http://localhost/soap/types',

'deleteTableResponse',

'localhostSoapTypes.deleteTableResponse_element'}

);

response_x = response_map_x.get('response_x');

return response_x.result;

}

// other methods here

// added test method

public static testMethod void testdeleteTable(){

localhostSoap lhsoap = new localhostSoap();

localhostSoap.Root_PortType rport = new localhostSoap.Root_PortType();

System.assertEquals(0, rport.deleteTable('localhost',3579,'test') );

}

}

What i am doing wrong here?

thank you very much

cheenathcheenath
Nothing wrong. You can not make a web service callout from the test method.


nellymnjnellymnj

but I can't deploy this code...

any suggestion please? thank you

cheenathcheenath
I think "Methods defined as TestMethods do not support Web service callouts, test skipped" is just
a warning. There should be someother reason for not deploying.


nellymnjnellymnj

I am deploying from Eclipse, when I run test cases it is a warning, but the deployment fails because of that, there is no other error (test coverage is 83 %).

I'll submit print screen tomorrow 

nellymnjnellymnj
I could not place a print screen here, but here is the deployment log:
Code:
*** Deployment Log ***
Result: FAILED
Executed on: February 6, 2008 8:43:39 AM EST
Reason: More than one problem occurred.  See below for details.

# Deployed From
   Project name: NetricsInt
   Username: nellimor@gmail.com
   Endpoint: https://www.salesforce.com/services/Soap/u/10.0

# Deployed To
   Username: forefront@forefrontcorp.com
   Endpoint: https://www.salesforce.com/services/Soap/u/10.0

# Deployed Component (<namespace>.<name> | <type> | <id> | <action>):
   (1) localhostSoap | ApexClass | Add
   (2) localhostSoapTypes | ApexClass | Add

# Compile Results (<namespace>.<name> | <type> | <success> | <problem>):
   (1) localhostSoap | ApexClass | true | n/a
   (2) localhostSoapTypes | ApexClass | true | n/a

# Delete Results (<namespace>.<name> | <type> | <success> | <problem>):
   n/a

# Test Results:
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped
  localhostsoap Methods defined as TestMethod do not support Web service callouts, test skipped

 
how can I deploy that? - thank you very much for your time
cheenathcheenath
This looks like an issue with the eclipse plugin. I will let them know.


nellymnjnellymnj
Thank you very much cheenath,
should i be able to deploy using Ant?
cheenathcheenath
No, ant deploy task will also have the same problem.

You can avoid making the callout from test (just comment out the callout part)
and you will be able to deploy.




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/xml'); // Or other appropriate MIME type like application/json
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