$user->uid is always 1 when running automated tests In my automated tests, I create some users.

  debug('moderator_user: '.$this-&gt;moderator_user-&gt;uid);
  debug('editor_user: '.$this-&gt;editor_user-&gt;uid);


outputs

'moderator_user: 2'
'editor_user: 4'


So I would think that 

global $user;
$this-&gt;drupalLogin($this-&gt;editor_user);
debug('currently logged in as '.$user-&gt;uid);


would output

'currently logged in as: 4'


but instead it shows,

'currently logged in as: 1'


It seems to be correctly logging user 4 because 

$this-&gt;drupalLogin($this-&gt;editor_user);
$edit = array(
  'title' =&gt; $this-&gt;randomName(),
);
$this-&gt;drupalPost("node/add/{$this-&gt;content_type}", $edit, t('Save'));
$node = $this-&gt;drupalGetNodeByTitle($edit['title']);

debug('Draft was created by user with uid '.$node-&gt;workbench_moderation['current']-&gt;uid);


yields

'Draft was created by user with uid 4'


So what's going on?
It happens exactly what described in the documentation page for DrupalWebTestCase::drupalLogin().


  Please note that neither the global $user nor the passed-in user object is populated with data of the logged in user. If you need full access to the user object after logging in, it must be updated manually. If you also need access to the plain-text password of the user (set by drupalCreateUser()), e.g. to log in the same user again, then it must be re-assigned manually. For example:

  // Create a user.
  $account = $this-&gt;drupalCreateUser(array());
  $this-&gt;drupalLogin($account);
  // Load real user object.
  $pass_raw = $account-&gt;pass_raw;
  $account = user_load($account-&gt;uid);
  $account-&gt;pass_raw = $pass_raw;