2015-05-05 1 views
0

Класс:нужно 100% результат в тесте класса: В PageReference

public with sharing class contactInsert { 
    public contact myC{get;set;} 
    public contactInsert(){ 
     myC = new Contact(); 
    } 
    public PageReference iSave(){ 
     insert myC; 
     return new pageReference('/'+myC.id); 
    } 
} 

Page:

<apex:page controller="contactInsert"><br> 
    <apex:form ><br> 
     <apex:pageBlock > 
      <apex:pageBlockSection > 
       <apex:inputField value="{!myC.firstname}"/> 
       <apex:inputField value="{!myC.lastname}"/> 
       <apex:inputField value="{!myC.email}"/> 
       <apex:inputField value="{!myC.phone}"/> 
      </apex:pageBlockSection> 
      <apex:pageBlockButtons > 
       <apex:commandButton value="Save" action="{!iSave}"/> 
      </apex:pageBlockButtons> 
     </apex:pageBlock> 
    </apex:form> 
</apex:page> 

Я создал тестовый класс, но не могу восстановить PageReference:

@isTest 
public with sharing class TestcontactInsert { 
    @isTest 
    private static void myTest(){ 
     contact c = new contact(firstname='fnam',lastname='lnam',email='[email protected]',phone='89898989'); 
     insert c; 

     PageReference pageRef = Page.InsertContact; 
     Test.setCurrentPage(pageRef); 

     ContactInsert ci = new ContactInsert(); 
     ci.iSave(); 
    } 
} 

ответ

0

Вам понадобится myC Контактное лицо на ci контакту, который еще не был вставлен. Если вы этого не сделаете, вы получите исключение ссылки Null из строки insert myC;.

 Смежные вопросы

  • Нет связанных вопросов^_^