I would go either by grouping tests as you stated in your question or by exception. If just few cases are the exception, your test in that cases must expect, that you start as admin. My idea in Java Pseudocode:
@Test
public void someTestWithDifferentUser() {
logout();
logInAsDifferentUser();
doSomeStuff();
}
My other Idea is to introduce User
class which could look like this:
public class User{
private String username;
private String password;
public User(String username, String password){
this.username = username;
this.password = password;
}
public String getUsername(){
return username;
}
public String getPassword(){
return password;
}
}
Then, in your tests you would have one global variable:
public static final User DEFAULT_USER = new User("admin","AdminSecretPassword");
and your tests would look like this:
@Test
public void doAdminStuff(){
loginAsUser(DEFAULT_USER);
doAdminStuff;
}
@Test
public void doUserStuff(){
loginAsUser(new User("testytester","testytest"));
doUserStuff();
}
Where the @BeforeMethod
would avoid the login completly.