Salesforce 如何在控制器扩展类中的类内调用方法?
我正在尝试为控制器扩展编写一个测试类。此控制器扩展中有另一个类。这个类有几个方法Salesforce 如何在控制器扩展类中的类内调用方法?,salesforce,force.com,Salesforce,Force.com,我正在尝试为控制器扩展编写一个测试类。此控制器扩展中有另一个类。这个类有几个方法 public class Extension_Account { public Extension_Account(ApexPages.StandardController controller) { public class Class1 { public Class1() { / * code here*/ }
public class Extension_Account
{
public Extension_Account(ApexPages.StandardController controller)
{
public class Class1
{
public Class1()
{
/ * code here*/
}
public String getMethod()
{
/* code here */
}
}
}
}
如何在测试类中访问getMethod方法
在我的测试类中,我能够访问Class1的构造函数,但不确定如何访问其他方法
public with sharing class TestExtension_Account
{
static testMethod void TestPrint()
{
Account a = new Account();
//a.Name='Test Account';
a.FirstName='TestFirst Name';
a.LastName='Test Last Name';
a.BillingStreet='Test billing Street';
a.BillingCity='Test Billing City';
a.BillingState='Test Billing State';
a.BillingCountry='Test Billing country';
a.BillingPostalCode='Test PostCode';
insert a;
PageReference pageRef = Page.printaddressaccount;
pageRef .getParameters().put('id',a.id);
Test.setCurrentPageReference(pageRef);
ApexPages.StandardController controller = new ApexPages.StandardController(a);
Extension_Account ae = new Extension_Account(controller);
ae.getClass1();
ae.getMethod()// gives a compiler error Method does not exist or incorrect signature
}
}
如果您的扩展类有一个返回Class1实例的getClass1方法,那么您可以从该实例访问这些方法,例如ae.getClass1.getMethod