With the core testing, how do I set a database variable? I am trying to establish a test suite for my project using the core testing module. But I can't get past such a trivial thing as setting a database variable.

A lot of tutorials on the web tell you to use $this-&gt;drupalVariableSet - e.g.: 

public function setUp() {
  parent::setUp(array('my_module'));
  $this-&gt;drupalVariableSet('my_module_var', 42);
}


This throws "Call to undefined method Mymoduletest::drupalVariableSet()" - so it looks like it has been depreciated at some point.

Using variable_set, e.g.:

public function setUp() {
  parent::setUp(array('my_module'));
  variable_set('my_module_var', 42);
}


does not produce an error, but the setting has no effect (i.e. the variable has its default value when it is used in one of the my test cases.

Any help will be appreciated.
drupalVariableSet() has been removed as per Remove drupalVariableSet.

variable_set() is the function you should use. In fact, DrupalWebTestCase::setUp() uses it for some persistent variables used from Drupal core, right after the call to drupal_install_system().

  // Perform the actual Drupal installation.
  include_once DRUPAL_ROOT . '/includes/install.inc';
  drupal_install_system();

  $this-&gt;preloadRegistry();

  // Set path variables.
  variable_set('file_public_path', $this-&gt;public_files_directory);
  variable_set('file_private_path', $this-&gt;private_files_directory);
  variable_set('file_temporary_path', $this-&gt;temp_files_directory);

  // Set the 'simpletest_parent_profile' variable to add the parent profile's
  // search path to the child site's search paths.
  // @see drupal_system_listing()
  // @todo This may need to be primed like 'install_profile' above.
  variable_set('simpletest_parent_profile', $this-&gt;originalProfile);


As long as the following conditions are met, using variable_set() should work as expected.


The test class derives from DrupalWebTestCase and not from DrupalTestCase
variable_set() is called after parent::setUp()
The name of the persistent variable used in variable_set() doesn't contain typos