You need to sign in to do that
Don't have an account?
anvesh@force.com
Need to increse below test code coverage for simple trigger ?
I had written Test class for below sample trigger code. But it covered only 56% code coverage. I did all correct. can anyone make it 100% ?
Trigger Code :
trigger AcUpdate on Account (Before Insert,before update) {
for(Account A : Trigger.new){
If( A.SE2_Id__c == '20004')
A.name = 'RBC WEALTH MANAGEMENT';
If( A.SE2_Id__c == '20002' )
A.name = 'JJB HILLIARD LYONS';
If( A.SE2_Id__c == '20000' )
A.name = 'FTB ADVISORS INC';
If( A.SE2_Id__c == '20005' )
A.name = 'BB&T SECURITIES LLC';
If( A.SE2_Id__c == '20003' )
A.name = 'KEY INVESTMENT SERVICES';
}
}
Test Class :
@IsTest
public class AcUpdate_Test{
public static testMethod void main(){
Account ac = new Account ();
ac.name = 'RBC WEALTH MANAGEMENT';
ac.Status__c = 'Active';
ac.SE2_Id__c = '25546';
ac.Channel__c = 'Bank';
insert ac;
ac.SE2_Id__c = '25346';
ac.name = 'RBC WEALTH MANAGEMENT1';
update ac;
Account ac1 = new Account ();
ac1.name = 'JJB HILLIARD LYONS';
ac1.Status__c = 'Active';
ac.SE2_Id__c = '25586';
ac1.Channel__c = 'Bank';
insert ac1;
ac.SE2_Id__c = '22546';
ac1.name = 'RBC WEALTH MANAGEMENT12';
update ac1;
Account ac2 = new Account ();
ac2.name = 'Test Account3';
ac2.Status__c = 'Active';
ac2.SE2_Id__c = '125456';
ac2.Channel__c = 'Bank';
insert ac2;
ac2.SE2_Id__c = '12546';
ac2.name = 'RBCSD WEALTH MANAGEMENT12';
update ac1;
Account ac3 = new Account ();
ac3.name = 'Test Account4';
ac3.Status__c = 'Active';
ac2.SE2_Id__c = '21254';
ac3.Channel__c = 'Bank';
insert ac3;
ac2.SE2_Id__c = '15256';
ac3.name = 'RBC WEALTH MANAGEMENT31';
update ac3;
Account ac4 = new Account ();
ac4.name = 'Test Account5';
ac4.Status__c = 'Active';
ac4.Channel__c = 'Bank';
ac2.SE2_Id__c = '8546';
insert ac4;
ac2.SE2_Id__c = '5740';
ac4.name = 'RBC WEALTH MANAGEMENT41';
update ac4;
}
}
Trigger Code :
trigger AcUpdate on Account (Before Insert,before update) {
for(Account A : Trigger.new){
If( A.SE2_Id__c == '20004')
A.name = 'RBC WEALTH MANAGEMENT';
If( A.SE2_Id__c == '20002' )
A.name = 'JJB HILLIARD LYONS';
If( A.SE2_Id__c == '20000' )
A.name = 'FTB ADVISORS INC';
If( A.SE2_Id__c == '20005' )
A.name = 'BB&T SECURITIES LLC';
If( A.SE2_Id__c == '20003' )
A.name = 'KEY INVESTMENT SERVICES';
}
}
Test Class :
@IsTest
public class AcUpdate_Test{
public static testMethod void main(){
Account ac = new Account ();
ac.name = 'RBC WEALTH MANAGEMENT';
ac.Status__c = 'Active';
ac.SE2_Id__c = '25546';
ac.Channel__c = 'Bank';
insert ac;
ac.SE2_Id__c = '25346';
ac.name = 'RBC WEALTH MANAGEMENT1';
update ac;
Account ac1 = new Account ();
ac1.name = 'JJB HILLIARD LYONS';
ac1.Status__c = 'Active';
ac.SE2_Id__c = '25586';
ac1.Channel__c = 'Bank';
insert ac1;
ac.SE2_Id__c = '22546';
ac1.name = 'RBC WEALTH MANAGEMENT12';
update ac1;
Account ac2 = new Account ();
ac2.name = 'Test Account3';
ac2.Status__c = 'Active';
ac2.SE2_Id__c = '125456';
ac2.Channel__c = 'Bank';
insert ac2;
ac2.SE2_Id__c = '12546';
ac2.name = 'RBCSD WEALTH MANAGEMENT12';
update ac1;
Account ac3 = new Account ();
ac3.name = 'Test Account4';
ac3.Status__c = 'Active';
ac2.SE2_Id__c = '21254';
ac3.Channel__c = 'Bank';
insert ac3;
ac2.SE2_Id__c = '15256';
ac3.name = 'RBC WEALTH MANAGEMENT31';
update ac3;
Account ac4 = new Account ();
ac4.name = 'Test Account5';
ac4.Status__c = 'Active';
ac4.Channel__c = 'Bank';
ac2.SE2_Id__c = '8546';
insert ac4;
ac2.SE2_Id__c = '5740';
ac4.name = 'RBC WEALTH MANAGEMENT41';
update ac4;
}
}
Hi Anvesh,
You need to prepare the data which will meet the conditions in the test class to get the complete coverage.
In your data I see that no record has the value for SE2_Id__c field which is has the value in the trigger.
Try the below code
Regards,
Bhanu Mahesh