• David Rodríguez Rincón
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Technology Architecture Consultant
  • Accenture


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi

I'm going through the Developer Begin Trail, but I'm facing some issues to get the Developer Console to show up the right code coverage (Winter '16).
I tried many of the suggestions out there like uncheck the "Test/Always test run async", uncheck the "Store Only Aggregated Code Coverage", run from the BUILD section... nothing seems to work (and I'm pretty sure I'm covering at least some lines of code...)

The Class I'm testing is the one provided by Salesforce guys:
public class VerifyDate {
	
	//method to handle potential checks against two dates
	public static Date CheckDates(Date date1, Date date2) {
		//if date2 is within the next 30 days of date1, use date2.  Otherwise use the end of the month
		if(DateWithin30Days(date1,date2)) {
			return date2;
		} else {
			return SetEndOfMonthDate(date1);
		}
	}
	
	//method to check if date2 is within the next 30 days of date1
	private static Boolean DateWithin30Days(Date date1, Date date2) {
		//check for date2 being in the past
        	if( date2 < date1) { return false; }
        
        	//check that date2 is within (>=) 30 days of date1
        	Date date30Days = date1.addDays(30); //create a date 30 days away from date1
		if( date2 >= date30Days ) { return false; }
		else { return true; }
	}

	//method to return the end of the month of a given date
	private static Date SetEndOfMonthDate(Date date1) {
		Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
		Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
		return lastDay;
	}
}
and my Test Class looks as follow:
 
@isTest
private class TestVerifyDate {
    @isTest static void checkDatesWithin30Days(){
        Date dt1 = date.today();
        Date dt2 = dt1.addDays(15);
        Date dte = VerifyDate.CheckDates(dt1, dt2);
        System.assertEquals(dt2, dte);
    }
    
    @isTest static void checkDatesDate2BeforeDate1(){
        Date dt1 = date.today();
        Date dt2 =	 dt1.addDays(-15);
        Date dte = VerifyDate.CheckDates(dt1, dt2);
        
        //Get the last day of dt1 month
        Integer totalDays = Date.daysInMonth(dt2.year(), dt2.month());
		Date lastDay = Date.newInstance(dt2.year(), dt2.month(), totalDays);
		Date assertDate = lastDay;
        
        System.assertEquals(assertDate, dte);
    }
    
    @isTest static void checkDatesNotWithin30Days(){
        Date dt1 = date.today();
        Date dt2 =	 dt1.addDays(45);
        Date dte = VerifyDate.CheckDates(dt1, dt2);
        
        //Get the last day of dt1 month
        Integer totalDays = Date.daysInMonth(dt1.year(), dt1.month());
		Date lastDay = Date.newInstance(dt1.year(), dt1.month(), totalDays);
		Date assertDate = lastDay;
        
        System.assertEquals(assertDate, dte);
    }

}

No matter what I do, the Code Coverage is always 0% (the code coverage for the test classes in the examples, copy and pasting.... is also 0%)
Anyone giving me some help on this?
Thanks!!


 
Hi

I'm going through the Developer Begin Trail, but I'm facing some issues to get the Developer Console to show up the right code coverage (Winter '16).
I tried many of the suggestions out there like uncheck the "Test/Always test run async", uncheck the "Store Only Aggregated Code Coverage", run from the BUILD section... nothing seems to work (and I'm pretty sure I'm covering at least some lines of code...)

The Class I'm testing is the one provided by Salesforce guys:
public class VerifyDate {
	
	//method to handle potential checks against two dates
	public static Date CheckDates(Date date1, Date date2) {
		//if date2 is within the next 30 days of date1, use date2.  Otherwise use the end of the month
		if(DateWithin30Days(date1,date2)) {
			return date2;
		} else {
			return SetEndOfMonthDate(date1);
		}
	}
	
	//method to check if date2 is within the next 30 days of date1
	private static Boolean DateWithin30Days(Date date1, Date date2) {
		//check for date2 being in the past
        	if( date2 < date1) { return false; }
        
        	//check that date2 is within (>=) 30 days of date1
        	Date date30Days = date1.addDays(30); //create a date 30 days away from date1
		if( date2 >= date30Days ) { return false; }
		else { return true; }
	}

	//method to return the end of the month of a given date
	private static Date SetEndOfMonthDate(Date date1) {
		Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
		Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
		return lastDay;
	}
}
and my Test Class looks as follow:
 
@isTest
private class TestVerifyDate {
    @isTest static void checkDatesWithin30Days(){
        Date dt1 = date.today();
        Date dt2 = dt1.addDays(15);
        Date dte = VerifyDate.CheckDates(dt1, dt2);
        System.assertEquals(dt2, dte);
    }
    
    @isTest static void checkDatesDate2BeforeDate1(){
        Date dt1 = date.today();
        Date dt2 =	 dt1.addDays(-15);
        Date dte = VerifyDate.CheckDates(dt1, dt2);
        
        //Get the last day of dt1 month
        Integer totalDays = Date.daysInMonth(dt2.year(), dt2.month());
		Date lastDay = Date.newInstance(dt2.year(), dt2.month(), totalDays);
		Date assertDate = lastDay;
        
        System.assertEquals(assertDate, dte);
    }
    
    @isTest static void checkDatesNotWithin30Days(){
        Date dt1 = date.today();
        Date dt2 =	 dt1.addDays(45);
        Date dte = VerifyDate.CheckDates(dt1, dt2);
        
        //Get the last day of dt1 month
        Integer totalDays = Date.daysInMonth(dt1.year(), dt1.month());
		Date lastDay = Date.newInstance(dt1.year(), dt1.month(), totalDays);
		Date assertDate = lastDay;
        
        System.assertEquals(assertDate, dte);
    }

}

No matter what I do, the Code Coverage is always 0% (the code coverage for the test classes in the examples, copy and pasting.... is also 0%)
Anyone giving me some help on this?
Thanks!!