我正在尝试测试此代码。我需要设置控制器并设置参数。控制器。
visualForce 页面有一个标准的接触控制器
Public Class myClass{
public ApexPages.standardController controller {get; set;}
public string pid {get; set;}
//CONSTRUCTOR
public myClass(ApexPages.StandardController controller){
this.controller = controller;
pId = ApexPages.CurrentPage().getparameters().get('id');
}
测试班
@isTest
public class testMyClass{
static testMethod void myTest(){
PageReference pageRef = Page.myPage;
Test.setCurrentPageReference(pageRef);
//create contact
Contact cont = new Contact(name ='bob');
insert cont;
ApexPages.CurrentPage().getparameters().put('pid', cont[0].id);
ApexPages.StandardController sc = new ApexPages.standardController(cont[0]);
myClass sic = new myClass(sc);
ApexPages.currentPage().getParameters().put(?);
System.assertEquals('something here');
}
}