Testing 在Salesforce中测试返回页面引用的方法

Testing 在Salesforce中测试返回页面引用的方法,testing,salesforce,apex-code,visualforce,force.com,Testing,Salesforce,Apex Code,Visualforce,Force.com,我在控制器中有一个方法 public PageReference add() { insert technology; return null; } 技术是一个自定义对象。它有自己的getter和setter。如何在测试类中测试此方法您必须初始化控件并调用此方法: static testMethod void test(){ YourController contr = new YourContro

我在控制器中有一个方法

    public PageReference add() {
              insert technology;
              return null;
            }

技术
是一个自定义对象。它有自己的getter和setter。如何在测试类中测试此方法

您必须初始化控件并调用此方法:

static testMethod void test(){
    YourController contr = new YourController();
    contr.add();
}
希望有帮助

 public static testMethod void testMyController() {


   PageReference pageRef = Page.yourPageName;

   Test.setCurrentPage(pageRef);

   MyController controller = new MyController();
   controller.add();

}