Overview:
Trigger:
I wrote trigger on account object when ever inserting or updating the account record the the values in the billing address field are copied to shipping address field if the shipping address field is null.
Trigger:
trigger Account_trigger on Account (before insert,before update) {
if((trigger.isInsert || trigger.isUpdate)&&trigger.isBefore){
for(Account acc:trigger.new){
if(acc.ShippingAddress==null){
acc.ShippingCity = acc.BillingCity;
acc.ShippingCountry = acc.BillingCountry;
acc.ShippingLatitude= acc.BillingLatitude;
acc.ShippingLongitude = acc.BillingLongitude;
acc.ShippingPostalCode =acc.BillingPostalCode;
acc.ShippingState=acc.BillingState;
acc.ShippingStreet = acc.BillingStreet;
}
}
}
}
This trigger is working correctly.
My Requirement:
I trying to write the test class for the above trigger but the test class above code is not covered any percentages. How do I write tests that cover the above code?
Test Class:
public class Trigger_TestCase {
public static testmethod void myTriggerTestMeth(){
Account acc1 = new Account();
acc1.Name='acc1';
acc1.BillingCity ='Chennai' ;
acc1.BillingCountry='india';
acc1.BillingLatitude=5657.577;
acc1.BillingLongitude=7845.46;
acc1.BillingPostalCode='600075';
acc1.BillingState='tamil nadu';
acc1.BillingStreet='water well street';
acc1.ShippingCity=null;
acc1.ShippingCountry=null;
acc1.ShippingLatitude=null;
acc1.ShippingLongitude=null;
acc1.ShippingPostalCode=null;
acc1.ShippingState=null;
acc1.ShippingStreet=null;
insert acc1;
}
}