You need to sign in to do that
Don't have an account?
Test Class Not Coverage
Hi Friends,
I am trying to cover a test class for below Trigger. But it's not cover as well , yeah it's just 42% only . already i have inserted Account and Opportunity also. But Still it's Not Covering. Kindly give me a valid advise ! Why it's happening .
************************ Trigget *******************
*****************TEST CLASS ********************
Thanks In Advance...
Regards,
Soundar.
I am trying to cover a test class for below Trigger. But it's not cover as well , yeah it's just 42% only . already i have inserted Account and Opportunity also. But Still it's Not Covering. Kindly give me a valid advise ! Why it's happening .
************************ Trigget *******************
trigger OpportunityRollUp on Opportunity ( after insert, after update,after delete) { Set<ID> accSet = New Set<ID>(); List<Account> accList = New List<Account>(); If(Trigger.IsDelete){ for(Opportunity opp1 : Trigger.old){ /* Not Covered */ accSet.add(opp1.AccountId); /* Not Covered */ } } If(Trigger.IsUpdate){ for(Opportunity opp : Trigger.new){ if(opp.Amount != Trigger.oldMap.get(opp.id).amount && opp.AccountId != Null ){ accSet.add(opp.AccountId); /* Not Covered */ } } } if(!accSet.isEmpty()){ /* Below Aggregate Result is Not Covered */ for(AggregateResult age : [Select AccountId,sum(Amount)tot, avg(Amount)opAvg, Min(Amount)opMin, Max(Amount)opMax from opportunity Where AccountId IN :accSet GROUP BY AccountId]){ accList.add(New Account(Id = (ID)age.get('AccountId'), opportunity_Total_Amount__c = (Decimal)age.get('tot'), Opportunity_Average__c = (Decimal)age.get('opAvg'), Opportunity_Max__c = (Decimal)age.get('opMax'), Opportunity_Min__c = (Decimal)age.get('opMin'))); } } if(accList.size() > 0){ update accList; } }
*****************TEST CLASS ********************
@IsTest Public Class OpportunityRollUp_Test{ public static testMethod void oppRollup(){ //Insert Account Account acc = New Account(); acc.name = 'Test_Account'; acc.Account_Code__c = 'AP001'; acc.Opportunities_Total_Amount__c = '1000'; acc.Total_Opportunities__c = 5; acc.Opportunity_Average__c = 1000; acc.Opportunity_Min__c = 500; acc.Opportunity_Max__c = 1000; insert acc; system.debug('Insert Account Details' + acc); //insert CurrencyType CurrencyType__c ctype = New CurrencyType__c(); ctype.name = 'Test_Type'; ctype.Conversion_Rate__c = 50; ctype.ISO_Code__c = 'INR'; insert ctype; system.debug('Insert Currency Type details : ' + ctype); CurrencyType__c ctype1 = New CurrencyType__c(); ctype1.name = 'Test_Type'; ctype1.Conversion_Rate__c = 50; ctype1.ISO_Code__c = 'AUD'; insert ctype1; //Insert Oportunity Opportunity Opp = New Opportunity(); opp.name = 'Test_Opportunity'; opp.closeDate = System.today(); opp.stageName = 'Closed Won'; opp.Amount = 1000; opp.Currency__c = 'INR'; opp.USD_Amount1__c = 1000; opp.AccountId = acc.id; insert opp; system.debug('Insert Opp details : ' + opp); Opportunity Opp1 = New Opportunity(); Opp1.name = 'Test_Opportunity'; Opp1.closeDate = System.today(); Opp1.stageName = 'Closed Won'; Opp1.Amount = 1000; Opp1.Currency__c = 'INR'; Opp1.USD_Amount1__c = 1000; Opp1.AccountId = acc.id; insert opp1; Opp1.Currency__c = 'AUD'; update opp1; } }
Thanks In Advance...
Regards,
Soundar.
Update your test class like below
Let us know if this will help you
All Answers
Hope Your trigger code cover above 75%
mark it best answer if it resove your problem
thanks
vikas
I modified your test class ,you will get 100% coverage just copy paste my code.
If its work for you make my answer as best answer.
Update your test class like below
Let us know if this will help you
Your Code is Covering 100 % (What i am expecting). Really Thanks , and I understood as well where i did mistakes.
Thanks !!
Thanks For Your Quick Response. :)
Thanks !!
Soundar