You need to sign in to do that
Don't have an account?

Test method webservice call outs
Hi all
I have a webserive and I use the controller below to invoke the service. I also use the list returned by the webservice to render a data table in VF page.
class listControllerExtension
{
public List<mywebservice.myItems> getmyItems() {
mywebservice.MywebserviceServiceImplPort stub = new mywebservice.MywebserviceServiceImplPort();
myitems=(List<mywebservice.myItems>)stub.giveItems(orderNumber);
return myitems;
}
}
At the moment I am writing testMethod and stuck badly. Can some one give some hints on how to write test cases for a webservice callout? The testMethod I wrote would navigate to the page and do a webservice callout which is
Account acc2 = new Account (itemNumberr= '2342');
insert acc2;
PageReference pageRef = new PageReference('/'+123213);
Test.setCurrentPage(pageRef);
ApexPages.StandardController Qcontroller = new ApexPages.StandardController(acc2);
listControllerExtension qe = new listControllerExtension(QController);
qe.acct = acc2;
List<mywebservice.myItems> Dummy= qe.getmyItems();
I see this error in the test log
17:46:27.458|FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped
Thanks in advance
Ashwin
Can you please share if you got to solution
Hi,
Sorry for the delay with the reply. I was not getting my activation link for some strange reason hence I was not able to post.
The webservice calls will not be executed. You have to make sure that you set all the parameters of the page before the webservice is called. Say for example:
1. You have request parameters. Ensure in your PageReference the request parameter attributes are set properly otherwise you might have a test failure.
PageReference pageRef = new PageReference('/id?=123213');
Test.setCurrentPage(pageRef);
Once you reach the page.
2. Try to set other parameters in that Page like If your setting some attributes on commandlink, textbox, also actions on button that should be executed. All these will improve your test coverage.
If you had already fixed this in a new way do share.