+ Start a Discussion
Michael RuckerMichael Rucker 

Error: Method does not exist or incorrect signature: VerifyDate.SetEndOfMonthDate

I've been working on the Getting Started with Apex Unit Tests  and have run into a speed bump on the challenge. I have 91% coverage and have one last line to figure out. I've tried various combinations of assert. without any success.

The error message is:
Error: Method does not exist or incorrect signature: VerifyDate.SetEndOfMonthDate(Datetime) 

The bold section of code has the issue. I'm not sure how to assert the method properly, if that is even the way to do it. The class/methods do exists.

@istest 
private class TestVerifyDate {
@isTest static void testCheckDates() {
    datetime dteDate1 = VerifyDate.CheckDates(Date.newInstance(2015, 1, 1), Date.newInstance(2015, 1, 10));
        if(VerifyDate.DateWithin30Days(Date.newInstance(2015, 1, 1),Date.newInstance(2015, 1, 10))) {
            System.assertEquals(Date.newInstance(2015, 1, 10),Date.newInstance(2015, 1, 10));
        } else {
           System.assert(VerifyDate.SetEndOfMonthDate(dteDate1));
        }    
}


Any thoughts or direction someone could point me in? Thanks.
sfdcdevsfdcdev
SetEndOfMonthDate method is private in class definition,you cannot access it.You have to use the TestVisible annotation to allow test methods to access private or protected members of another class outside the test class.
 
@TestVisible 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;
    }

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_testvisible.htm
Michael RuckerMichael Rucker
Thanks. I've inserted @TestVisbile for each private method in this class. However running the test still fails code coverage on this line
User-added image
My test looks like this.
User-added image

Under the else for testCheckDates I've tried various combinations. 
System.assert(true) allows me to save the code an run the test, but only 91%

//VerifyDate.SetEndOfMonthDate(Date.newInstance(2015, 1, 1));       Gives me an error when I try to save the code test.
//System.assert(VerifyDate.SetEndOfMonthDate(dteDate1));  Gives me an error when I try to save the code test.

User-added image

I'm sure I'm missing something on the System.assert / System.assertequals line. I'll keep plugging away. Maybe that note about @TestVisible could be added to the Trailhead module. Seems like a little detail that is important.

Any other thoughts ? 


 
Michael RuckerMichael Rucker
There was another post about this. Basically don't use if else statement in tests. 
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AySOIA0

I'm getting closer to understanding this concept.
sfdcdevsfdcdev
Rida Akhtar 9Rida Akhtar 9

Hi this code is giving me 100% coverage.
Try this:

@istest 
private class TestVerifyDate {
@isTest static void testCheckDates() {
    datetime Date1 = VerifyDate.CheckDates(Date.newInstance(2015, 1, 1), Date.newInstance(2015, 1, 10));  
    datetime Date2 = VerifyDate.CheckDates(Date.newInstance(2015, 1, 1), Date.newInstance(2015, 2, 10));
    
  }
}

Vijayakumar DhanasekaranVijayakumar Dhanasekaran
Hi the following code gave me 100% coverage:

@isTest
public class TestVerifyDate {   
    
    @isTest
    static void testCheckDatesPositive(){
        Date dte = VerifyDate.CheckDates(Date.valueOf('2015-04-30'), Date.valueOf('2015-05-10'));
        system.assertEquals(dte,Date.valueOf('2015-05-10'));
    }
    
    @isTest
    static void testCheckDatesdate2GT30Daysdate1(){
        Date dte = VerifyDate.CheckDates(Date.valueOf('2015-04-30'), Date.valueOf('2015-06-30'));
        system.assertEquals(dte,Date.valueOf('2015-04-30'));
    }
    
    @isTest
    static void testCheckDatesdate2LTdate1(){
        Date dte = VerifyDate.CheckDates(Date.valueOf('2015-04-30'), Date.valueOf('2015-03-30'));
        system.assertEquals(dte,Date.valueOf('2015-04-30'));
    }
    
}