+ Start a Discussion
Ramana VRamana V 

Test class batch class update

Hi All,
I am facing issues with test class for batch apex. Please find below my classes.

Batch Apex:
global class conuserDeactivate implements Database.Batchable<sObject>{
    global Database.Querylocator Start(Database.BatchableContext BC)
		set<id> userId = new set<id>();
        List<contact> conList = [select id,User__c from contact where user__r.lastlogindate < =:syste.now().adddays(-14)];        
       for(contact c : caseList){
        string s = 'select isActive from user where id =: userid';    
        return Database.getQuerylocator(s);
    global void Execute(Database.BatchableContext BC, List<User> scope){      
        for(User u : scope){
            u.isActive = false;
        update scope;
    global void finish(Database.BatchableContext BC){

Test class:
public class conuserDeactivateTest {
    static testMethod void deactivateMethod() {
        List<sObject> us = Test.loadData(User.sObjectType, 'userResource');
        User u = (User)us[0];
        Id uid = u.id;    
        Contact c = new Contact();
        c.LastName = 'TestContact';
        c.UserB__c = uid;
        insert c;
        conuserDeactivate CUD = new conuserDeactivate();

I am facing issues in covering of for loop in start method. I am not able to get user based on last log in date in test class.
Please help me how to cover this in test class.
Thanks in Advance
Ramana V
Ryan Khan 1Ryan Khan 1
Any web developer to help me in; bestelectricsmoker.org (https://bestelectricsmoker.org/)