Is it possible to get some assistance on my code and test?
It seems like literally every test I write is passing with zero code coverage org wide.. I've spent the past 2 days on and off reading forums, doing trails and debugging. I feel like I may be at the point where a step back and another brain to tell me where I'm getting confused?
Please see below for just one of the Apex classes and test methods!
global with sharing class AccountingPeriodCreationService {
public static List accountingPeriod;
public static Date currentDate;
public static Date firstDayOfCurrentMonth;
public static Date lastDayOfCurrentMonth;
public static void createdAPLogic(){
Set firstDaysOfMonths = new Set();
accountingPeriod = new List (); // New list for accountingPeriod Object
// Create a list of dates for the next 10 years
for (Integer i = 0; i checkAccountingPeriodAlreadyExist = [SELECT Id, TEMP__c, AcctSeed__Start_Date__c, AcctSeed__End_Date__c FROM AcctSeed__Accounting_Period__c where TEMP__C IN :firstDaysOfMonths];
// For the ones that do exist, remove them from the list
for (AcctSeed__Accounting_Period__c ap : checkAccountingPeriodAlreadyExist) {
firstDaysOfMonths.remove(ap.TEMP__c);
}
// For the ones left, insert into the list
for (String dt : firstDaysOfMonths){
string currName = dt.replaceAll('.{3}$','');
Date currStart = Date.valueOf(dt);
Date currEnd = Date.valueOf(dt).addMonths(1).toStartofMonth().addDays(-1);
accountingPeriod.add(
new AcctSeed__Accounting_Period__c(
Name = currName,
AcctSeed__Status__c = 'Status',
AcctSeed__Start_Date__c = currStart,
AcctSeed__End_Date__c = currEnd
)
);
}
// Insert into the database
System.debug( 'accountingPeriod: ' + accountingPeriod.size());
List accountingPeriod = Database.insert(accountingPeriod, false);
}
}
Now the Test Class and one method. This is mega basic, literally to insert two items into the list, query the DB and see if there are 2 entries. (Which passes)
private class AccountingPeriodCreationServiceTest {
static testmethod void checkIfAlreadyExistsTest() {
AccountingPeriodCreationService CAP = new AccountingPeriodCreationService();
/* Pre requisites, insert Accounting Period */
List accountingPeriod;
Date currentDate;
Date firstDayOfCurrentMonth;
Date lastDayOfCurrentMonth;
Test.startTest();
accountingPeriod = new List (); // New list for accountingPeriod Object
Set firstDaysOfMonths = new Set();
for (Integer i = 0; i InsertResult = [SELECT Id, TEMP__c, AcctSeed__Start_Date__c, AcctSeed__End_Date__c FROM AcctSeed__Accounting_Period__c where TEMP__C IN :firstDaysOfMonths];
System.assertEquals(2, InsertResult.size());
}
}
I purposely included a carbon copy of the code for this instance, but zero coverage still
Have I just gotten this completely wrong?
Any help is appreciated. Thank you