I despair at the moment getting the code coverage on a newly created apex class. It's a manager class without without any sObject references which I plan to use for triggers and other manager classes.
My problem is the following: I wrote an apex test class to get the code coverage for the "ScheduleManager" class. Even though the test class passes and the assertequals method succeeds (also fails if I enter a wrong assertion), the code coverage for the given class is still 0%.
The method in my manager class looks like this:
public static TimeFrame CalculateScheduleByDate(Date startDate, Date endDate, Date scheduleStart, integer periodSchedule){
System.Debug('-->Entering ScheduleManager.CalculateScheduleByDate with parameters: StartDate=' + startDate.format() + ', EndDate=' + endDate.format() + ', ScheduleStart=' + scheduleStart.format() + ', PeriodSchedule='+ periodSchedule);
List<TimePeriod> periods = new List<TimePeriod>();
//Just to check: totalWeighting should be a full number at the end of the calculation.
Decimal totalWeighting = 0;
//-----Calculate the first Period-----//
//Identify the start of the first period (before the start date)
if (scheduleStart <> startDate){
//Calculate first weighting
decimal firstWeighting = CalculateWeight(startDate, scheduleStart, periodSchedule);
periods.add(new TimePeriod(startDate, scheduleStart, firstWeighting));
System.debug('Period ' + startDate.format() + ' - ' + scheduleStart.format() + ' - Weighting: ' + firstWeighting * 100 + '%');
totalWeighting = firstWeighting;
}
//-----Calculate periods in between-----//
Date currentPeriodStart = scheduleStart;
Date currentPeriodEnd = scheduleStart.addMonths(periodSchedule);
integer multiplier = 1;
while (currentPeriodStart.addMonths(periodSchedule) <= endDate){
periods.add(new TimePeriod(currentPeriodStart, currentPeriodEnd, 1));
System.debug('Period ' + currentPeriodStart.format() + ' - ' + currentPeriodEnd.format() + ' - Weighting: 100%');
currentPeriodStart = scheduleStart.addMonths(periodSchedule * multiplier);
currentPeriodEnd = scheduleStart.addMonths(periodSchedule * (multiplier+1));
multiplier = multiplier + 1;
totalWeighting = totalWeighting + 1;
}
//-----Calculate last period-----//
//Identify the start of the first period (before the start date)
if (currentPeriodStart <> endDate){
Date lastPeriodStart = currentPeriodStart;
Date lastPeriodEnd = currentPeriodStart.addMonths(periodSchedule);
//Calculate last weighting
//Same as for the first period: Weights differ in months
decimal lastWeighting = CalculateWeight(currentPeriodStart, endDate, periodSchedule);
periods.add(new TimePeriod(lastPeriodStart, endDate, lastWeighting));
totalWeighting = totalWeighting + lastWeighting;
System.debug('Period ' + lastPeriodStart.format() + ' - ' + endDate.format() + ' - Weighting: ' + lastWeighting * 100 + '%');
}
System.debug('Total Periods: ' + periods.Size());
System.debug('Total Weighting: ' + (totalWeighting * 100) + '%');
//Return
TimeFrame tf = new TimeFrame(startDate, endDate, scheduleStart, periodSchedule, totalWeighting, periods);
return tf;
}
My test class looks like this:
@isTest
public class ScheduleManagerTest {
public static TestMethod void ByDate_SameStartScheduleAndEndDay(){
Date startDate = Date.newInstance(2015, 01, 01);
Date scheduleStartDate = Date.newInstance(2015, 01, 01);
Date endDate = Date.newInstance(2015, 07, 01);
TimeFrame tf = ScheduleManager.CalculateScheduleByDate(startDate, endDate, scheduleStartDate, 1);
System.assertEquals(6, tf.TotalWeight);
}
}
As you can see in the debug log, the test runs successfuly.
But I stil have 0% code coverage:
I already did some research, but I haven't found any similar thread for this problem. Most of the test coverage threads handly the lack of test coverage on triggers. Does anybody have an idea on this? I am happy to share the full development if it helps.
Thanks in advance!
Best regards,
Konstantin
{}
pre-formatted text icon so that it's legible to anyone who reads it. It's always a good practice to look at the preview pane of your post to fix any problems before posting it.