为WebService写TestClass
比如我们有如下WebService代码
global class DemoApexWebService {
global class AccountInfo {
WebService String AccName;
WebService Integer AccNumber;
}
WebService static Account createAccount(AccountInfo info) {
Account acct = new Account();
acct.Name = info.AccName;
acct.AccountNumber = String.valueOf(info.AccNumber);
insert acct;
return acct;
}
}
TestClass的写法如下
@isTest
private class TestNewWebService
{
static testMethod void testNewWebService()
{
DemoApexWebService.AccountInfo acc = new DemoApexWebService.AccountInfo();
acc.AccName = 'ABC';
acc.AccNumber = 123;
DemoApexWebService.createAccount( acc );
Account[] a = [select AccountNumber from Account where AccountNumber = '123'];
System.assertEquals(a.size(), 1);
}
}