How to test a SF webService?

January 14, 2013

We can simply initialize the webService class and invoke the webService method in APEX. 

Example:

@isTest
private class testMyWebService
{
  
  
  static testMethod void testMyWebSvc()
  {
      SampleApexWebSvc.AccountInfo act = new SampleApexWebSvc.AccountInfo();
      act.AcctName = 'test';
      act.AcctNumber = 123;
      SampleApexWebSvc.createAccount( act );
      
      Account[] a = [select AccountNumber from Account where AccountNumber = '123'];
      System.assertEquals(a.size(), 1);
  }
}


Reference: http://boards.developerforce.com/t5/Apex-Code-Development/Testing-APEX-Web-services/m-p/268557/highlight/true#M46798 

You Might Also Like

0 comments

Popular Posts

Twitter