0

I have problems with coverage percent during testing my class. It always shows 0%. What is wrong with code, can you help me? Here are my codes

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

@isTest
private class TestVerifyDate {

    @isTest static void testCheckDatesin30Days(){
        Date d1=VerifyDate.CheckDates(Date.newInstance(2008, 08, 08), Date.newInstance(2008, 08, 30));
        System.assertEquals(Date.newInstance(2008, 08, 30), d1);
    }

    @isTest static void testCheckDatesoutof30Days(){
       Date d1=VerifyDate.CheckDates(Date.newInstance(2008, 08, 08), Date.newInstance(2008, 09, 25));
        System.assertEquals(Date.newInstance(2008, 08, 31), d1);        
    }
}

enter image description here

And in test logs it shows completed, not passed as in tutorial enter image description here

| improve this question | | | | |
0

There is an issue with developer console in Winter' 16 so try to run your test class from Class detail page itself and then check developer console for code coverage. It will show 100%

enter image description here

Winter '16 - In Developer Console, running tests synchronously does not generate code coverage

| improve this answer | | | | |
  • It is really strange, but trailhead challenge checker accepted my answer after I manually ran test in user mode... Anyway, thank you for advice. – Ilqar Rasulov Oct 19 '15 at 7:29
  • yeh that is correct. It is because test code coverage stored in object and I think trailhead check value from there. – Himanshu Oct 19 '15 at 7:31
  • as I have said this is known issue they will fix that. – Himanshu Oct 19 '15 at 7:31
  • thanks, Himanshu, very much! there wasn't a word about it in trailhead, hope devs will fix it – Ilqar Rasulov Oct 19 '15 at 7:37
  • cool! select the answer and close this question so that everybody can have clear idea about this issue. – Himanshu Oct 19 '15 at 7:40
0

Navigate to your apex classes from lhs of your org setup page ,then open the class which you need to test. Click on RUN TEST .This might solve your issue.

| improve this answer | | | | |
  • thanks Mohammed, i did exactly what you've written, it helped me – Ilqar Rasulov Oct 19 '15 at 7:39
0

For me, as well, the Test Code Coverage only appears if I run the tests from Setup. This is a way in which you can run multiple tests at once: Setup > Build > Develop > Apex Test Execution > Select Tests.. > (select your namespace and test classes) > Run

This way I get both the code highlight and coverage percentage in Developer Console immediately after the tests completes. On the other hand, if I run the tests directly from Developer Console I get non of those.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.