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
Steve ChadbournSteve Chadbourn 

Testing Controller Extensions

I'm trying to write unit tests for a controller extension and am getting a Salesforce error when I try and run it.

Here is part of the controller extension I'm trying to test:

Code:
public class newClaimWizardControllerExtension
{
 private final Case new_case;
 
 public newClaimWizardControllerExtension(ApexPages.StandardController stdController)
 {
  this.new_case = (Case)stdController.getRecord();
 }

 public PageReference policiesPage()
 {
  return Page.newClaimWzrdPolicies;
 }
}

Here is the test class:


Code:
public class newClaimWizardControllerExtensionTests 
{
 public static testMethod void testMyController() 
 {
  newClaimWizardControllerExtension controller = new newClaimWizardControllerExtension(new ApexPages.StandardController());
  
  // test page references
  PageReference policiesPage = controller.policiesPage();
  system.assertEquals(policiesPage, Page.newClaimWzrdPolicies); 
 }
}

 And here is the error I'm getting when I run it:

Code:
An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact support@salesforce.com. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience.

Thank you again for your patience and assistance. And thanks for using Salesforce!

Error ID: 879885452-10 

I'm guessing its to do with the way I'm passing a standard controller into the controller extansion constructor. I have tried all sorts of different ways to do this without success. Help!

BTW, do I have to test all the action methods that simply return a page?




Steve ChadbournSteve Chadbourn
OK, I managed to get past the error message by passing in null in place of the StdController.

My next problem is I'm failing my first, simple test. Here is the code I'm testing:

Code:
public PageReference policiesPage()
{
 return Page.newClaimWzrdPolicies;
}

and here is the test:

Code:
PageReference policiesPage = controller.policiesPage();
system.assertEquals(policiesPage, Page.newClaimWzrdPolicies); 

and this is the error:

Code:
System.Exception: Assertion Failed: 
Expected: System.PageReference[/apex/newclaimwzrdpolicies], 
Actual: System.PageReference[/apex/newclaimwzrdpolicies]

I can't see any difference between the expected and the actual. What am I doing wrong?

 
 

dchasmandchasman
FYI we've made the StandardController createable in Summer '08 which will let you really test your extensions the way you want and need to.
Steve ChadbournSteve Chadbourn

That's good news Doug. I look forward to Summer 08.

Any ideas why my unit test is failing?