function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
notsosmartnotsosmart 

System.NullPointerException: Attempt to de-reference a null object

My Test Method results in the above error on a number of lines.  I'm thinking it's one thing tripping it all up.  What is in common on all of them is that they are references to my controller extension.  

 

Excerpts from the Test Class are:

 

@isTest(seeAllData=true)
private class Test_TripRpt_Ext{

private static ApexPages.StandardController ctl; 
private static TripRptExt ext; 
private static ApexPages.StandardController ctlWithReport; 
private static TripRptExt extWithReport; 

private static User mockAdminUser; 
private static User mockManagerUser; 
private static User mockEmployeeUser; 
private static User mockContractorUser; 

private static Trip_Report__c r; 

//private static List<Attendee_Item__c> eil;
private static List<AttendeeLineItem> ail;   
private static List<OpportunityLineItem> oil;  
 
static{

  //Build mock data 
  setupReportWithItem();

  //Instantiate and empty controller. 
  ctl = new ApexPages.StandardController(new Trip_Report__c()); 
  ext = new TripRptExt(ctl); 

  //Instantiate a full controller. 
  ctlWithReport = new ApexPages.StandardController(r); 
  extWithReport = new TripRptExt(ctlWithReport);
  extWithReport.isUpdate = true;

 }

 

------

The ERROR Lines:

 

system.assertEquals( null, ext.getReportItemsMessage() );

 

 

system.assertEquals( new Trip_Report__c(), ext.getTripReport() ); 

 

for(AttendeeLineItem lineItem : extWithReport.getAttendeeItemListNotDeleted() ){

 system.debug( 'Item: ' + lineItem ); 

 

and so on - all are ext. or extWithReport. items.

 

I'd greatly appreciate any clues on this.  Thanks

 

 

 

 

HariDineshHariDinesh

Hi,

 

As per my observation here you are missing some basic with writing Test method.

Please go through the links which will helpful to understand about test methods.

 

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_unit_tests_running.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm

 

If still need any help give the complete code and where you are getting errors?