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
JimmyMacJimmyMac 

Need Help Creating Test Class...

I am new to Apex, and the testing has me a bit confused as to how to perform certain types of tests:

 

Below is my code, can some one help me see how to write a test for this as well as answer the questions below?

1. How to test a method that is defined as a PageReference? (i.e how to CALL it in a test method?)

2. When creating test data "on the fly" how long does the test data stay available (i.e If I create test data in the FIRST test method,  is the data gone right after that test completes or is that test data available to all the rest of the test methods I have defined. So Can I just add the test data ONCE, for ALL my tests or do I need to do it for EACH test method I have defined?

 

 

public PageReference processViewHousehold() {
 
        //Householdis is a PUBLIC variable contains list of id's
        if(householdid != null)
        {
            List<Account> HouseHold = new List<Account>(
            [
            Select id                    
            from account
            where payout__Households__c = :householdid
        
            ]
            );
        
        
           List<Id> myClientIdList = new List<id> ();
       
           for(Account a : HouseHold){
               myClientIdList.add(a.id);
           }       
   
           ClientIdList = myClientIdList;
        }
        
      
        return null;
    }

MJ Kahn / OpFocusMJ Kahn / OpFocus
The Visualforce Developer's Guide provides a good example of how to write unit tests for VF controllers and extensions. See ”Testing Custom Controllers and Controller Extensions" in http://www.salesforce.com/us/developer/docs/pages/index_Left.htm.

Data you create for unit tests exists only for the lifetime of the test method. You can write a helper method that creates test data, then call the method from each of your test methods.
JimmyMacJimmyMac

Thanks...

 

But first the link you gave doesn't seem to exist anymore ("Got the dreaded OOps.... message")

 

Secondly, I have read some testing articles already, but I haven't seen any examples of how to test a method defined as a PageReference data type.

 

So if someone can please provide me with a testing method example of a PageReference method I would really appreciate it.

MJ Kahn / OpFocusMJ Kahn / OpFocus
Try the PDF: http://www.salesforce.com/us/developer/docs/pages/salesforce_pages_developers_guide.pdf. There's a good example in there that focuses on testing controller methods.
JimmyMacJimmyMac

Not sure what is happening but the link you are giving me is saying "Oops not found"...

MJ Kahn / OpFocusMJ Kahn / OpFocus
Try the URL without the period at the end. (I'm writing from my iPad, and it may be putting the period in the URL instead of after it.)

If general, you can find these documents via developer.force.com