I'm trying to write a unit test code for the below method but despite using @TestVisible annotation also I'm not able to access the local variables inside my test class. Is there anything I'm missing.
public void inactiveUsers(){
// List<String> excludedUserList = getExcludedUsers();
List<user> UserList = new List<user>();
List<Messaging.SingleEmailMessage> emailsList = new List<Messaging.SingleEmailMessage>();
@TestVisible DateTime dateBefore_90days = Date.today().addDays(Integer.valueof(Label.Secure_provisioning_90_days_notification.trim())*-1);
@TestVisible string d = dateBefore_90days.format('yyyy-MM-dd');
system.debug(Integer.valueof(Label.Secure_provisioning_90_days_notification.trim())*-1+'###'+d);
string query = 'SELECT Id,email,username,lastlogindate FROM User WHERE IsActive = TRUE and DAY_ONLY(convertTimezone(LastLoginDate)) <= '+ d;
system.debug('###query##'+query);
selectedUsers = Database.query(query);
system.debug('Secure_provisioning_90days_notification list### '+selectedUsers);
for(User record: selectedUsers) {
record.IsActive = false;
UserList.add(record);
Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();
// email.setSenderDisplayName('Optum Inactive User Notification');
email.setToAddresses(new String[]{record.email});
email.setCCAddresses( new String[]{Label.Secure_provisioning_cc_email_address});
email.setTargetObjectId(record.id);
email.setSaveAsActivity(false);
String body = getHTMLBody90days(record);
email.setHtmlBody(body);
email.setSubject('Your Access has been revoked');
email.setUseSignature(false);
emailsList.add(email);
}
here is my test code.
static testMethod void myTest() {
DeactivateInactiveUsers.dateBefore_90days = Date.today(); // getting error: Variable does not exist: dateBefore_90days
DeactivateInactiveUsers.d = 'some value';
}
Any help would be appreciated.