I am trying to create a test class for my apex trigger but I am not able to reach the code coverage. does anyone how I can reach the code coverage?
Here is trigger
trigger AccountInformation on Charter__c (Before Update)
{
for(Charter__c c: trigger.new)
{
List<Account> accts = [SELECT Invoice_Contact_1_Email__c,
Invoice_Contact_2_Email__c,
Invoice_Contact_3_Name__c,
Invoice_Contact_2_Name__c,
Invoice_Contact_1_Name__c,
Invoice_Contact_3_Phone__c,
Invoice_Contact_2_Phone__c,
Invoice_Contact_1_Phone__c,
Invoice_Contact_3_Email__c
FROM account WHERE ID =:c.Account__c];
for (Account a: Accts)
{
c.Invoice_Contact_1__c = a.Invoice_Contact_1_Name__c;
c.Invoice_Contact_2__c = a.Invoice_Contact_2_Name__c;
c.Invoice_Contact_3__c = a.Invoice_Contact_3_Name__c;
c.Invoice_Contact_1_Phone__c = a.Invoice_Contact_1_Phone__c;
c.Invoice_Contact_2_Phone__c = a.Invoice_Contact_2_Phone__c;
c.Invoice_Contact_3_Phone__c = a.Invoice_Contact_3_Phone__c;
c.Invoice_Contact_1_Email__c = a.Invoice_Contact_1_Email__c;
c.Invoice_Contact_2_Email__c = a.Invoice_Contact_2_Email__c;
c.Invoice_Contact_3_Email__c = c.Invoice_Contact_3_Email__c;
}
}
}
This trigger is suppose to insert values from an account to my custom object called charter before an update to the record. I have tested this in the sandbox and it is working well.
Here is my test class
@isTest
private class AccountingInforTesting {
static testMethod void Test_Infor(){
charter__c con = new charter__c(name='Test Charter 10', Account__c = '001Z000000eX3xlIAC', DCS__c = True);
insert Con;
con.name = 'Test';
update con;
delete con;
}
}
The test class has given me only 25% of code coverage.
Any help on how I can make this work is appreciated. Thanks