You need to sign in to do that
Don't have an account?
Heather_Hanson
HELP! Need to boost code coverage from 74% to 75%
I created 1 new Trigger and a Test Class and it is saying that my overall code coverage is now 74%...but the test itself passes.
Maybe I'm missing something in my test? Although I have a very similar trigger already and it is in production so not sure why this one is causing problems...
Here is the Trigger:
Here is the TestClass:
Maybe I'm missing something in my test? Although I have a very similar trigger already and it is in production so not sure why this one is causing problems...
Here is the Trigger:
Trigger OppContactResi on Opportunity (before insert, before update) { set<Id> AccountIds = new set<Id>(); for (Opportunity o: trigger.new) { AccountIds.add(o.AccountId); } map<Id, Account> AccountContactMap = new map<Id, Account>(); list<Account> AccConts = new list<Account>(); AccConts = [Select Id, Name, (Select Id, Name, Contact_Role__c from Contacts Where Contact_Role__c = 'MAIN CONTACT') from Account where Id IN : AccountIds]; for(Account acc : AccConts){ AccountContactMap.put(acc.Id, acc); } for (Opportunity o: trigger.new) { if(o.Contact__c == null && o.RecordTypeID == '0121H0000019Lna'){ Account Acc = AccountContactMap.get(o.AccountId); if(Acc != null){ List<Contact> conts = new list<Contact>(Acc.Contacts); if(conts.size() == 1){ o.Contact__c = conts[0].Id; } } } } }
Here is the TestClass:
@isTest public class OppContactResiTEST { static testMethod void createAccount() { Account a = new Account(); a.Name = 'Test'; a.RecordTypeId = '0121H0000019LnX'; a.Language__c = 'ENGLISH'; insert a; System.debug('created account'); //Then create a non Main contact Contact c = new Contact(); c.RecordtypeId = '0121H0000019LnZ'; c.FirstName = 'Paul'; c.LastName = 'Test'; c.AccountId = a.id; c.Contact_Role__c = 'BILLING CONTACT'; c.Phone = '514-722-5656'; insert c; System.debug('created signing contact'); //Then create another Main contact Contact ci = new Contact(); ci.FirstName = 'Bob'; ci.LastName = 'Test'; ci.AccountId = a.id; ci.Contact_Role__c = 'MAIN CONTACT'; ci.Phone = '514-722-5656'; insert ci; System.debug('created non-signing contact'); //Create Top Shelf Settings Scout__TopShelf_Settings__c ts = new Scout__TopShelf_Settings__c(); ts.Scout__TopShelf_Username__c = 'selectcom'; ts.Scout__TopShelf_Password__c = 'Fhtmdvp2'; ts.Scout__My_Account__c = a.id; insert ts; System.debug('created top shelf settings'); //Now create an opportunity Opportunity o = new Opportunity(); o.AccountId = a.id; o.Name = 'Test -'; o.Service_Agreement_Type__c = 'Residential Services'; o.StageName = 'NEW - CALL IN'; o.Type = 'SALES'; o.CloseDate = Date.today(); o.RecordTypeId = '0121H0000019Lna'; o.Requested_Install_Time__c = ' In the morning (9:00am-12:00pm)'; o.Internet_Requested__c = TRUE; o.Existing_Internet_Provider__c = 'Bell'; o.Existing_Internet_Service__c = 'Yes'; o.If_Bell_is_internet_on_line_or_Dry_Loop__c = 'Line'; o.Language__c = 'ENGLISH'; o.Router_Option__c = 'Customer already has router'; insert o; System.debug('created opportunity'); } }
I would be checking for other triggers or classes that have sub standard coverage and look to boost them.
Do a check using your favourite tool. Mine is Sublime but the Eclipse IDE can do similar features.
Looking at the test code above I will say that whilst you are "covering" the lines, there are no asserts. So how do you know that the code is working and doing what it is supposed to do? How will you know that it continues to work if you change another trigger/class/PB?
I would add at a minimum something like the following:
Note also that your trigger is an "insert or update" trigger and that your code only tests for an insert. I would up the class to also cover the update. I would also test for negative results. No contact value set.
The Test class is that - a way to test your code.
Regards
Andrew
All Answers
Relace it in Trigger also
try this
I would be checking for other triggers or classes that have sub standard coverage and look to boost them.
Do a check using your favourite tool. Mine is Sublime but the Eclipse IDE can do similar features.
Looking at the test code above I will say that whilst you are "covering" the lines, there are no asserts. So how do you know that the code is working and doing what it is supposed to do? How will you know that it continues to work if you change another trigger/class/PB?
I would add at a minimum something like the following:
Note also that your trigger is an "insert or update" trigger and that your code only tests for an insert. I would up the class to also cover the update. I would also test for negative results. No contact value set.
The Test class is that - a way to test your code.
Regards
Andrew
The issue was that a test was failing a lot on an installed package due to required fields not being fulfilled. Luckily I was able to modify that class and correct the issue and then everything else sorted out.