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();
}
}
Please add Shipping_Status__c in you test class like below
@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;
shipmentOrder.Shipping_Status__c ='Test';
insert shipmentOrder;
Test.startTest();
ragStatusUpdate batch = new ragStatusUpdate();
database.executebatch(batch);
Test.stopTest();
}
}