You need to sign in to do that
Don't have an account?
Cynthia Rodgers 12
Test Class is only at 33%
I have created an apex class and a test class but my code coverage is at 33% and I need it to be at 75% or higher. I am not sure how to increase the test class i created using test generator, can you tell me how to increase my code coverage?
My Apex class is evaluating the account fields TSS Designation = Temporary and TSS Temporary End Date. When the designation is temporary and the end date is today, then this class will update those fields to null. I have this class setup on the scheduler to run daily.
apex class: update tss fields
public class update_tss_fields implements Schedulable, Database.Batchable<sObject>
{
public void execute( SchedulableContext context )
{
Database.executeBatch( this );
}
public Database.QueryLocator start( Database.BatchableContext context )
{
return Database.getQueryLocator
( 'SELECT Id, TSS_Designation__c, TSS_Temporary_End_Date__c '
+ 'FROM Account '
+ 'WHERE TSS_Temporary_End_Date__c = TODAY'
);
}
public void execute( Database.BatchableContext context, List<Account> accounts )
{
for ( Account account : accounts )
{
account.TSS_Designation__c = null;
account.TSS_Temporary_End_Date__c = null;
}
update accounts;
}
public void finish( Database.BatchableContext context )
{
// nothing to do here...
}
}
My Apex class is evaluating the account fields TSS Designation = Temporary and TSS Temporary End Date. When the designation is temporary and the end date is today, then this class will update those fields to null. I have this class setup on the scheduler to run daily.
apex class: update tss fields
public class update_tss_fields implements Schedulable, Database.Batchable<sObject>
{
public void execute( SchedulableContext context )
{
Database.executeBatch( this );
}
public Database.QueryLocator start( Database.BatchableContext context )
{
return Database.getQueryLocator
( 'SELECT Id, TSS_Designation__c, TSS_Temporary_End_Date__c '
+ 'FROM Account '
+ 'WHERE TSS_Temporary_End_Date__c = TODAY'
);
}
public void execute( Database.BatchableContext context, List<Account> accounts )
{
for ( Account account : accounts )
{
account.TSS_Designation__c = null;
account.TSS_Temporary_End_Date__c = null;
}
update accounts;
}
public void finish( Database.BatchableContext context )
{
// nothing to do here...
}
}
All Answers
@isTest private class update_tss_fields_Test{ @testSetup static void setupTestData(){ test.startTest(); Account account_Obj = new Account(Name = 'Name705', Household__c = false, Top_Prospect__c = false, Banker_Originated__c = false, Converted_Lead__c = false, Profile_Complete__c = false, Treasury_Customer__c = false, LLC_BI__Automated_Financials__c = false, LLC_BI__Employee_Relationship__c = false, LLC_BI__Financials_Opt_Out__c = false, LLC_BI__Reg_O_Relationship__c = false, LLC_BI__Backup_Withholding_Exempt_Indicator__c = false, LLC_BI__Backup_Withholding_N_A_Indicator__c = false, LLC_BI__Form_W8_Model_2_Indicator__c = false, LLC_BI__Form_W8_Owner_Trust_Indicator__c = false, LLC_BI__Form_W8_Signer_Indicator__c = false, LLC_BI__Form_W8_Treaty_Limitation_Provision_Ind__c = false, LLC_BI__Form_W8_Treaty_Qualified_Resident_Status__c = false, LLC_BI__Form_W9_Seperat_TIN_Certification_Ind__c = false, LLC_BI__Previous_Financial_Account_Indicator__c = false, nSBA__Bankruptcy__c = false, nSBA__Business_At_Least_12_Months_Old__c = false, nSBA__Convicted_Criminal__c = false, nSBA__Current_Lawsuit__c = false, nSBA__Exporter__c = false, nSBA__Federal_Employee__c = false, nSBA__Form_4506T_Account_Transcript_Req__c = false, nSBA__Form_4506T_Form_W2_1099_Series_Trans_Req__c = false, nSBA__Form_4506T_Has_Authority_To_Sign__c = false, nSBA__Form_4506T_Record_Of_Account_Req__c = false, nSBA__Form_4506T_Return_Transcript_Req__c = false, nSBA__Form_4506T_Verification_Of_Nonfiling__c = false, nSBA__Possible_Affiliations_Indicator__c = false, nSBA__Prior_SBA_Loan__c = false, Franchise__c = false, Wealth_Client__c = false, CL_Best_Efforts__c = false, CL_Bulk_Mandatory__c = false, CL_FHA__c = false, CL_FNLMC__c = false, CL_FNMA__c = false, CL_GNMA__c = false, CL_Jumbo__c = false, CL_Single_Mandatory__c = false, CL_TPO__c = false, CL_USDA__c = false, CL_VA__c = false, CL_Warehouse_Client__c = false, BDO_Qualified_Checkbox__c = false, Woman_Owned_Business__c = false, CL_FHLMC__c = false, Active_Seller__c = false, nBRIDGER__OFAC_CSR_Relationship__c = false, nBRIDGER__OFAC_Reg_W_Relationship__c = false, nSBA__Disability_Insurance__c = false, Debt_Funds__c = false, COR__c = false, Charge_Account_Analysis__c = false, Dual_Admins__c = false, Dummy_Relationship_Name__c = false, Exception_Pricing__c = false, Mortgage_Finance__c = false, Non_Accrual__c = false, Perform_Annual_Review__c = false, Permanent_Waiver__c = false, SCRA__c = false, Signature_Services_Client__c = false, Single_Admin__c = false, TCB_Employee__c = false, TSS_Designation__c = 'Temporary', TSS_Temporary_End_Date__c = Date.today(), Temporary_Waiver__c = false, iFACs__c = false, Current_Customer__c = false, Product_Gap__c = false, LLCLP__Primary_Borrower__c = false, nSBA__Applicant_Is_Presently_Suspended__c = false, nSBA__Business_Has_Outstanding_Debt__c = false, nSBA__Is_Government_Guaranteed_Loan_Defaulted__c = false, nSBA__Is_Government_Guaranteed_Loan_Delinquent__c = false, nSBA__No_Former_SBA_Employee_Is_Owner_Partner__c = false, nSBA__No_GS13_Government_Employee_Owns_10_Pct__c = false, nSBA__No_Member_of_Congress_Owns_10_Percent__c = false, nSBA__No_SBAC_Or_SCORE_Member_Owns_10_Percent__c = false, nSBA__No_SBA_Employee_Owns_10_Percent_Or_More__c = false, nSBA__Prior_Government_Loan__c = false, nSBA__Revenues_From_Gambling_Or_Sexual_Nature__c = false, Top_Client__c = false); Upsert account_Obj; test.stopTest();
}
static testMethod void testBatch(){
update_tss_fields obj01 = new update_tss_fields();
Database.executeBatch(obj01, 200);
}
}
See updated test class, this should work for you.
Let me know If you have any concern.
Thanks
Thanks for replying back. I just tested it and now i am getting no code coverage and it says 0/0 test methods passed.
If not then try below one.
The above class will not run. Pleas run the below class.
I tested my code before posting it and I had a 100% test coverage.