You need to sign in to do that
Don't have an account?

increase code coverage
I am writing a test class for a main class that will insert a value into a transaction table based on updates to specific fields in the account object.
I have written the class but i am not able to increase the test coverage.
any help will be appreciated.
I have written the class but i am not able to increase the test coverage.
any help will be appreciated.
public class TX_RecordUpdate { static Set<String> accfields; // Account fields to be monitored static { List<TX__c> customsettingfields = [select Name from TX__c where Contact__c = true];////field value getting from custom setting accfields = new Set<String>(); for(TX__c customsettingfield : customsettingfields) { accfields.add(customsettingfield.name); // adding the listof fields system.debug('accfields will give' + Email, FirstName, LastName, MailingCity); } } public static void checkAccount(List<Account> accountList, Map<Id, Account> oldAccounts) { List<TX__c> insertevents = new List <TX__c> (); for(Account acc : accountList){ Account oldacc = oldAccounts.get(acc.Id); for(String acckey : accfields) { ///// test code coverage not going into this for loop if(acc.get(acckey) != oldacc.get(acckey)) { insertevents.add(new TX__c (Action__c = 'Success'); }////// } } if(!insertevents.isEmpty()) { try { insert insertevents; } catch (Exception Ex){ } } } } Test class: @isTest(seeAllData=true) private class Test{ private static testMethod void myTest() { Account testAccount = new Account(Name='test'); insert testAccount; Contact testContact = new Contact(); testContact.LastName='testName'; testContact.email = 'testname@gmail.com'; testContact.AccountId = testAccount.id; insert testContact; TX__c cs = new TX__c (Name='Billing',Field__c= True);///inserting custom setting data insert cs ; Account testAccount2 = new Account(Id=testAccount.Id); update testAccount2; Map<Id, Account> oldMap = new Map<Id, Account>{testAccount.Id => testAccount}; Test.starttest(); TX_RecordUpdate.checkAccount(new List<Account>{ testAccount2 }, oldMap); Test.stoptest(); } }
All Answers
Give a try by calling constructor in your test class code:
TX_RecordUpdate newObj = new TX_RecordUpdate();