You need to sign in to do that
Don't have an account?
Not getting 75% code coverage
On deploy the trigger i am not getting 75% coverge.
My triggers looks like
trigger MileageCostTrigger on GP_Calc__c (before insert,before update) {
for (GP_Calc__c gp: trigger.new)
{
Milage__c mc = Milage__c.getValues(gp.Program__c);
if(mc != null)
{
gp.Mileage_Costs__c = mc.Miles__c * gp.Mileage__c ;
}
}
}
and class looks like
@isTest
private class MileageCostTestCase {
static testMethod void myUnitTest() {
Opportunity oppNew = new Opportunity();
oppNew.Name = 'Test Opp';
oppNew.StageName = 'Ticketing';
oppNew.CloseDate = System.now().date();
insert oppNew;
GP_Calc__c gp = new GP_Calc__c();
gp.Program__c = 'AA';
gp.From__c = '1';
gp.To__c= '2';
gp.Tax__c =23;
gp.Mileage__c = 23;
gp.Mileage_Costs__c = 0.0210;
gp.Opportunity__c = oppNew.Id;
insert gp;
Milage__c mc = new Milage__c();
mc.Name ='Anil';
mc.Miles__c = 0.0210;
insert mc;
List<GP_Calc__c> listGp = new List<GP_Calc__c>();
GP_Calc__c gpNew = [SELECT Id, Mileage_Costs__c, Mileage_Cost__c FROM GP_Calc__c WHERE Id =:gp.id];
gpNew.Mileage_Costs__c = mc.Miles__c;
listGp.add(gpNew);
if (listGp != null && !listGp .isEmpty())
{
Database.update(listGp);
}
}
}
note: insert oppNew; this line is not coverd
Please please help - I have been trying to get my head around this all day
Any help - much apprecaited
Regards
Just change ths
gp.Program__c = 'AA';
to
gp.Program__c = 'Anil';
As you have given 'Anil' in the name field of custom setting.
let me know if any issues.
@ shashikant sharma
Its not working again 74 % code covergae
and line that not covered is
insert oppNew;
trigger MileageCostTrigger on GP_Calc__c (before insert,before update) {
for (GP_Calc__c gp: trigger.new)
{
Milage__c mc = Milage__c.getValues(gp.Program__c);
if(mc != null)
{
gp.Mileage_Costs__c = mc.Miles__c * gp.Mileage__c ;
}
}
}
the below line in trigger is not covered i dont understand why it was.
gp.Mileage_Costs__c = mc.Miles__c * gp.Mileage__c ;
hi deepakM
Try to put the gp.Program__c in set<string> and do the query for it.
select Miles__c from Milage__c where .....
Thanks
Anu
anuraj
Milage__c is schema object.
i changed my trigger as below
but even though it not wokring
for (GP_Calc__c gp: trigger.new)
{
Milage__c obj = [SELECT Id,Name FROM Milage__c WHERE Name =:gp.Program__c];
if(obj != null)
{
gp.Mileage_Costs__c = obj.Miles__c * gp.Mileage__c ;
}
}
deepak
You have given the where condition as name = :gp.Program__c;
but in the test class
gp.Program__c = 'AA';
and
mc.Name ='Anil';
please look into this code.
Thanks
Anu
i already change this
gp.Program__c = 'AA'; to gp.Program__c = 'Anil';
but no progress