0

我创建此控制器以在 visualforce 页面上显示自定义批准相关的记录列表,其中包含名为 Car_Maintenance 的对象的 Actor 的签名(照片)。它在我的沙箱上完美运行,但我无法编写测试类以将其部署到生产中。

控制器和我的测试类如下。我的头痛从测试课的第 53 行开始。错误消息是审批记录中的某些字段是必需的。

控制器


    public MaintenanceRequestController() {

    }


    public Map<Id,User> userMap { get; set; }
    public List<ProcessInstanceStep> processInstanceList { get; set; }

    public MaintenanceRequestController(ApexPages.StandardController controller) {
      userMap = new Map<Id, User>();
      processInstanceList = new List<ProcessInstanceStep>();
      Id recordId = ApexPages.CurrentPage().getparameters().get('id');
  
      processInstanceList = [Select id,ActorId, Actor.Name,CreatedDate, Actor.Title, Actor.FirstName , ProcessInstanceId, 
                              Actor.LastName, StepStatus, ProcessInstance.TargetObjectId
                              from ProcessInstanceStep
                              WHERE ProcessInstance.TargetObjectId = :recordId];
       for (ProcessInstanceStep step : processInstanceList){
            userMap.put(step.ActorId, new User(Signature__c=null));
       }
        userMap.putAll([SELECT Id,Name,Signature__c FROM User WHERE Id = :userMap.keySet()]);
    
        }

}```

test Class 

```@IsTest
public class CarMaitenanceControllerTest{
static testMethod  void CarMaitenanceController(){
   
     Car__c veh = new Car__c (  Category__c='Pickup', Color__c='Red', Condition__c='Excellent', 
     Description__c='Test Vehicle',  Engine_Number__c='XXX',
     Matriculation__c = 'IT-00011', Make__c='Toyota', Year__c ='2017', Model__c='Colorado');
          insert veh;
    
    
    Part_Accessories_Reception__c par = new Part_Accessories_Reception__c();
    par.Date__c = System.today();
    par.Provider__c = 'Other';
    
     
    insert par;
    
    Part_Accessories__c pa = new Part_Accessories__c(Name = 'filter');
    insert pa;
    
    
    Part_Accessories_Inventory__c pai =  new Part_Accessories_Inventory__c();
    pai.Quantity_Received__c =7771;
   
    pai.Part_Accessories_Reception__c = par.ID;
    pai.Part_Accessories__c = pa.Id;
    
    insert pai; 
    
    
    
    
     Car_Maintenance__c carMain = new Car_Maintenance__c();
       
          carMain.Car__c = veh.ID;
          carMain.Cheque_Bank__c = '444-Cmmm'; 
          carMain.Company__c = 'FFP';
          carMain.Date__c = System.today();

         insert carMain;
     
        Maintenance_Details__c mdet = new Maintenance_Details__c();
        mdet.Description__c      = 'qiuyiuyi';
        mdet.Quantity__c         =555;
        
        mdet.Maintenance__c      = carMain.Id;
        mdet.Description__c      ='kjalhsdhfklasdf';
        mdet.Cost__c             = 999;
        mdet.Part_Accessories_Inventory__c = pai.Id;

        insert mdet;
        
        Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
        app.setObjectId(carMain.Id);
        Approval.ProcessResult result = Approval.process(app);
        
        
        ProcessInstance pi = new ProcessInstance ();
        pi.TargetObjectId = carMain.Id;
        pi.Status ='Approved';
        Insert pi;
        
        ProcessInstanceStep pis = new ProcessInstanceStep();
        pis.ProcessInstanceId = pi.Id;
        Insert pis;

    Test.setCurrentPageReference(new PageReference('CarMaintenanceView')); 
    System.currentPageReference().getParameters().put('id', veh.ID);
    CarMaintenanceController CRC = new CarMaintenanceController();
    MaintenanceRequestController mrc = new MaintenanceRequestController();
    
}

}```
4

1 回答 1

0

你能确定哪个是测试类的第 53 行,是给你带来麻烦的那个吗?以及具体的错误?

可能是生产中的必填字段与沙盒中的字段不同,当您插入测试数据时,这会让您感到困惑。

于 2021-07-19T15:28:44.173 回答