You need to sign in to do that
Don't have an account?
Masechaba Maseli 8
Help with batchable class test
Hi all
I have a batch class that I am getting very litte test coverage for, can someone please assist. Lines 9 to 18 are not being covered.
I have a batch class that I am getting very litte test coverage for, can someone please assist. Lines 9 to 18 are not being covered.
global class ragStatusUpdate implements Database.Batchable<sObject>{ global Database.QueryLocator start(Database.BatchableContext BC) { string query = 'select id, Update_Rag_Status_Time__c from Shipment_Order__c where Shipping_Status__c != \'POD Received\' AND Shipping_Status__c != \'On Hold\'AND Shipping_Status__c != \'Cancelled\'AND Shipping_Status__c != \'Shipment Pending\' AND Shipping_Status__c != \'Cancelled - With fees/costs\' AND Shipping_Status__c != \'Cancelled\'AND Shipping_Status__c != \'Cancelled - No fees/costs\' AND Shipping_Status__c != \'Customs Clearance Docs Received\' '; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Shipment_Order__c>scope ) { list<Shipment_Order__c> SO = new list<Shipment_Order__c>(); for(Shipment_Order__c s : scope) { s.Update_Rag_Status_Time__c = TRUE; SO.add(s); } update SO; } global void finish(Database.BatchableContext BC){ } }
@isTest private class RagStatusTest { static testMethod void testMethod1() { Account testClient = new account(Name='TestingClient',Client_Status__c = 'Prospect',Estimated_Vat__c = 123,CSE_IOR__c='0050Y000001LTZO'); insert testClient; Contact testcontact = new Contact(LastName='Maseli',AccountId=testClient.Id); insert testcontact; country_price_approval__c cpa = new country_price_approval__c( name ='Serbia', Billing_term__c = 'DAP/CIF - IOR pays', Airwaybill_Instructions__c = 'User IOR Address'); insert cpa; IOR_Price_List__c testIOR = new IOR_Price_List__c(); testIOR.Client_Name__c = testClient.Id; testIOR.Name = 'Serbia'; testIOR.IOR_Fee__c = 1; insert testIOR; Shipment_Order__c shipmentOrder = new Shipment_Order__c(); shipmentOrder.Account__c = testClient.Id; shipmentOrder.IOR_Price_List__c = testIOR.Id; shipmentOrder.Client_Contact_for_this_Shipment__c = testcontact.Id; shipmentOrder.Shipment_Value_USD__c = 123; shipmentOrder.Who_arranges_International_courier__c ='Client'; shipmentOrder.Tax_Treatment__c ='DAP/CIF - IOR pays'; shipmentOrder.Ship_to_Country__c = cpa.Id; shipmentOrder.Update_Rag_Status_Time__c = TRUE; insert shipmentOrder; Test.startTest(); ragStatusUpdate batch = new ragStatusUpdate(); database.executebatch(batch); Test.stopTest(); } }
All Answers
The execute method of your Batchable is only called if the query in the start method returns records. So try to debug the number of records in your test class.
Through this debug, you will get to know what is missing in your test data.
Thanks,
Aman
I did exactly that and got 100% coverage earlier. Thank you for the assistance everyone.