コントローラー拡張機能クラスにあるクラス内のメソッドを呼び出す方法は?
-
27-10-2019 - |
質問
コントローラー拡張機能のテストクラスを作成しようとしています。このコントローラー拡張機能には、別のクラスがあります。そして、このクラスにはいくつかの方法があります。
public class Extension_Account
{
public Extension_Account(ApexPages.StandardController controller)
{
public class Class1
{
public Class1()
{
/ * code here*/
}
public String getMethod()
{
/* code here */
}
}
}
}
テストクラスでメソッドgetMethodにアクセスするにはどうすればよいですか?
私のテストクラスでは、Class1のContructorにアクセスできますが、他の方法に到達する方法がわかりません
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()
;
所属していません StackOverflow