I require to login certain users among the test users created in test classes.
Each user is created as follows:
User user = new User(Alias='test', Email='test@none.com');
insert user;
I create multiple such sample users.
My business logic class checks for logged in users via:
List<AuthSession> sessions = [Select UserId From AuthSession];
UserId in this list tells me which users are logged in.
How can I login my user programmatically in my test case?
Edit:
I run a scheduled Apex class which assigns a particular lead from a Queue to one among list of users. Scheduler runs as Admin. It needs to check which among UserA, UserB or UserC is Logged in.
To make this check I use AuthSession to determine which users are logged in. UserInfo contains information about Admin which is irrelevant. Under this light is there alternative to AuthSession?
In test case, I create mock users and need to simulate some among them are logged in. So that I can test if my business logic works well to skip assignment for 'Not logged in users'.