When creating automated tests in Drupal 7, you can use $this->drupalCreateUser() to create a user with specific permissions, but what if you want to create a user with a specific role? Here's how to set up a user with the role "administrator", for example within your setUp() method:
// create a new user with some permissions you need; then log in.
$perms = user_role_permissions(array(array_search('administrator', user_roles()) => 'administrator'));
$perms = array_keys($perms[array_search('administrator', user_roles())]);
$admin = $this->drupalCreateUser($perms);