How can I write users table data in custom file? I have a number of users in my site,I have developed custom module for drupal mail functionality.

But I want to write test cases for custom module.

then here is the problem is how can I get the (db_select) users table data and write down in .test file.

for example in .module file we use like this:

$select = db_select('{users}', 'users');
$select -&gt; addField('users', 'name', 'users_name');
$select -&gt; addField('users', 'uid', 'uid');
$select -&gt; addField('users', 'mail', 'users_mail');
$select -&gt; addField('users', 'created', 'users_created');
$select -&gt; addField('users', 'access', 'users_access');
$select -&gt; addField('user_relationships', 'requester_id', 'requester_id');
$select -&gt; addField('users_roles', 'rid', 'role_id');
$select -&gt; addField('users_user_relationships', 'mail', 'users_user_relationships_mail');
$select -&gt; leftjoin('user_relationships', 'user_relationships', "users.uid=user_relationships.requestee_id");
$select -&gt; leftjoin('users', 'users_user_relationships', "user_relationships.requester_id=users_user_relationships.uid");
$select -&gt; innerjoin('users_roles', 'users_roles', "users.uid = users_roles.uid");
$select -&gt; condition('users.status', 0, '&lt;&gt;');
$select -&gt; condition('users_roles.rid', array(
  '4',
  '5'
), 'IN');
$subresult = $select -&gt; execute();


and i have wrote .test file like this

&lt;?php
class BiTestMailsTests extends DrupalWebTestCase {
protected $privileged_user;
public static function getInfo() {
  return array(
    'name' =&gt; 'Test Mails',
    'description' =&gt; 'Tests for the mail module.',
    'group' =&gt; 'Test Mail Group',
 );
 }
public function setUp() {
   parent::setUp(array('mails'));

   }

public function testmail() {
    // Create an administrative user.
    $account = $this-&gt;drupalCreateUser(array('administer actions'));
    $this-&gt;drupalLogin($account);

      //database files
    $results= db_select('users','u')-&gt;fields('u',array('uid','name','mail','created','access'))-&gt;execute()-&gt;fetchAll();
    if($results){
     foreach($results as $res){
     $user_fields = user_load($res -&gt; uid);
     $this-&gt;verbose('language:'.$language);
     $string= 'uid:'.$res-&gt;uid.' ,name:'.$res-&gt;name.' ,mail:'.$res-&gt;mail.',created date:'.$res-&gt;created.',Access:'.$res-&gt;access.'\n\r';
     $this-&gt;verbose($string);
    }
    }
    }
    }


but temporary user created and that values are getting.
i don't want temp values,i want database USERS table values.
How can I write down users information(name and email) in .test file?
Your just need get your select put it in FOREACH and write down in file.(something like below code can help you_

$results= db_select('users','u')-&gt;fields('u',array('uid','name','email'))-&gt;execute()-&gt;fetchAll();
if($results){
     $fh=fopen(drupal_get_path('module',   'yourcustommodulename').'/usertest.txt','w+');
     foreach($results as $res){
     $string= 'uid:'.$res-&gt;uid.' ,name:'.$res-&gt;name.' ,email:'.$res-&gt;email.'\n\r';
    fwrite($fh,$string);
  }
  fclose($fh);


}