+ Start a Discussion
Cameron SeitzCameron Seitz 

Apex Test Class For Batch Class

I'm trying to write a test class for some Batch Apex that I've written and I'm not sure how to go about getting the needed coverage on Apex like this. Below I've included what I currently have for my Batch Class. Could someone point me in the right direction? Thank you! 
global class placementTimecardAuditFlag implements Database.Batchable<sObject>, Database.Stateful {

  List<jstcl__TG_Timesheet__c> query = [SELECT jstcl__Placement__r.Name FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.ts2__Status__c ='Active' AND jstcl__Placement__r.jstcl__Timesheet_Period__c != 'Weekly Split' AND jstcl__Week_Ending__c = LAST_N_DAYS:15 AND jstcl__Status__c = 'Pending'];
    Set<String> encounteredNames = new Set<String>();
    Set<String> duplicateNames = new Set<String>();

global Database.QueryLocator start(Database.BatchableContext bc) {
        for(jstcl__TG_Timesheet__c item : query){
      return Database.getQueryLocator('SELECT Id,Checkbox1__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.Name IN :duplicateNames');}

 global void execute(Database.BatchableContext BC, List<jstcl__TG_Timesheet__c> a){
    for(jstcl__TG_Timesheet__c b : a) {
        if(b.Checkbox1__c = True){
           b.Checkbox1__c = False;
        else{b.Checkbox1__c = True;}}
update a;        
global void finish(Database.BatchableContext BC){}

Check this for sample code - http://www.infallibletechie.com/2013/11/test-class-for-batch-apex-in-salesforce.html