+ Start a Discussion
DoctorDoctor 

Test Method failures

I am having my first attempt at writing a test method. I am slowly getting the coverage up, but I also manage to get a failure on each test.

 

Any suggestions would be much appreciated.

 

Test Method:

 

 

@isTestprivate class DBGExtensionTest2 {

 

// Unit Test for general record creation  

static testMethod void createGCTest() {

PageReference pageRef = Page.GroupCallPageDBG;

Test.setCurrentPage(pageRef);

contactSearchDBGExtension controller = new contactSearchDBGExtension();

Group_Call__c GroupCall = new Group_Call__c (Call_Type__c = 'Journal Club', CallStart__c = system.now(), Session_Length__c = '45 mins', State_National_ACtivity__c = 'State', PeopleTrained__c = '1 - 5');

controller.save();

system.assertEquals('Journal Club', GroupCall.Call_Type__c);

system.assert(GroupCall.CallStart__c != null);

system.assertEquals('45 mins', GroupCall.Session_Length__c);

system.assertEquals('1 - 5', GroupCall.PeopleTrained__c);

}

 

  // Unit Test for fullSearch pageRef

static testMethod void fullSearchTest1() {

 

PageReference pageRef = Page.GroupCallPageDBG;

Test.setCurrentPage(pageRef);

contactSearchDBGExtension controller = new contactSearchDBGExtension();

controller.setName('PRM');

controller.setState('VIC');

controller.setSpecialty('General Practice');

List<Contact> l1 = controller.getResult();

controller.fullSearch();

system.assert( l1.size() == 0 );

controller.getConRes();

system.assertEquals( 'PRM', controller.getName());

system.assertEquals( 'VIC', controller.getState());

system.assertEquals( 'General Practice', controller.getSpecialty());

controller.allContactselected = true;

controller.getselectedContacts();

controller.saveSelectedContacts();

}

 

// Unit Test for partSearch pageRef

  static testMethod void partSearchTest() {

 

PageReference pageRef = Page.GroupCallPageDBG;

Test.setCurrentPage(pageRef);

contactSearchDBGExtension controller = new contactSearchDBGExtension();

controller.setName('PRM');

controller.setState('NSW');

List<Contact> l2 = controller.getResult();

controller.partSearch();

system.assert( l2.size() >= 0 );

controller.getConRes();

system.assertEquals( 'PRM', controller.getName());

system.assertEquals( 'NSW', controller.getState());

controller.allContactselected = true;

controller.getselectedContacts();

controller.save();

}

}

 

The errors are as follows:

 

DBGExtensionTest2.createGCTest
System.NullPointerException: Attempt to de-reference a null object
Class.contactSearchDBGExtension.save: line 19, column 20
Class.DBGExtensionTest2.createGCTest: line 11, column 8External entry point
System.NullPointerException: Attempt to de-reference a null object
Class.contactSearchDBGExtension.save: line 19, column 20 
Class.DBGExtensionTest2.partSearchTest: line 93, column 9External entry point

DBGExtensionTest2.fullSearchTest

System.NullPointerException: Argument 1 cannot be null

Class.contactSearchDBGExtension.SaveSelectedContacts: line 148, column 50Class.DBGExtensionTest2.fullSearchTest1: line 36, column 9External entry point 

 

 

Message Edited by Doctor on 02-13-2010 12:51 AM
Anand@SAASAnand@SAAS
Profile your methods using either "System.debug" or by running the test methods in the "Sytem Log" console. Looks liek you have bugs in your code that is not settings references correctly or your SOQL queries are returning empty/null results.