Test Methods

The following are the system static methods for Test.

Name Arguments Return Type Description
setCurrentPage PageReference page Void A Visualforce test method that sets the current PageReference for the controller.
setCurrentPageReference PageReference page Void A Visualforce test method that sets the current PageReference for the controller.
setFixedSearchResults ID[] opt_set_search_results Void Defines a list of fixed search results to be returned by all subsequent SOSL statements in a test method. If opt_set_search_results is not specified, all subsequent SOSL queries return no results.

The list of record IDs specified by opt_set_search_results replaces the results that would normally be returned by the SOSL queries if they were not subject to any WHERE or LIMIT clauses. If these clauses exist in the SOSL queries, they are applied to the list of fixed search results.

For more information, see Adding SOSL Queries to Unit Tests.

startTest   Void Marks the point in your test code when your test actually begins. Use this method when you are testing governor limits. You can also use this method with stopTest to ensure that all asynchronous calls that come after the startTest method are run before doing any assertions or testing. Each testMethod is allowed to call this method only once. All of the code before this method should be used to initialize variables, populate data structures, and so on, allowing you to set up everything you need in order to run your test. After you call this method, the limits that get applied are based on either the first DML statement (like INSERT, DELETE, and so on) or the first Web service invocation. The following example tests trigger limits:
test.starttest();
// The first significant statement is below  
    
// Trigger context limits applied - 
    
Account s = new Account(name='test');
insert s;
The following example tests webService limits:
test.starttest();
String holder = wsclass.executeWebService(foo);
stopTest   Void Marks the point in your test code when your test ends. Use this method in conjunction with the startTest method. Each testMethod is allowed to call this method only once. After calling this method, any post assertions are done in the original context. All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously.
Note
Asynchronous calls, such as @future or executeBatch, called in a startTest, stopTest block, do not count against your limits for the number of queued jobs.
© Copyright 2000-2009 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.