You need to sign in to do that
Don't have an account?
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.
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.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_testvisible.htm
My test looks like this.
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.
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 ?
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AySOIA0
I'm getting closer to understanding this concept.
https://developer.salesforce.com/forums/ForumsMain?id=906F000000091SnIAI
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));
}
}
@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'));
}
}
@isTest
private class TestVerifyDate {
@isTest static void testCheckDatesWithin() {
Date dateReturned = VerifyDate.CheckDates(Date.newInstance(2020, 9, 30), Date.newInstance(2020, 10, 10));
System.assertEquals(dateReturned, dateReturned);
}
@isTest static void testCheckDatesNotWithin() {
Date dateReturned = VerifyDate.CheckDates(Date.newInstance(2020, 9, 30), Date.newInstance(2020, 12, 10));
System.assertEquals(dateReturned, dateReturned);
}
}
No need to do much, just think of cases here:
1. Date1 and Date2 difference less than 30 days
2. Date 1 and Date2 difference more than 30 days
TRY BELOW CODE:
@isTest
public class TestVerifyDate
{
@isTest
public static void Test()
{
VerifyDate.CheckDates( Date.newInstance(2021,08,30), Date.newInstance(2021,09,28)); // case 1
}
@isTest
public static void Test1()
{
VerifyDate.CheckDates( Date.newInstance(2021,08,20), Date.newInstance(2021,09,28)); //case 2
}
}