1

I am doing Apex Unit Testing and in the Challenge, this is my code. I have this error of module not visible. Please help

 @isTest
private class VerifyDateTest{
    @isTest static void CheckDatesTest1(){
    Date Date1 = VerifyDate.CheckDates(System.today(),System.today()+1);
    Date Date2 = VerifyDate.CheckDates(System.today(),System.today()+15);
    System.assertequals(System.today(),System.today()+15, Date2);
    }

    @isTest static void CheckDatesTest2(){
    Date Date1 = VerifyDate.CheckDates(System.today(),System.today()+1);
    Date Date2 = VerifyDate.CheckDates(System.today(),System.today()+60);
    Integer Lastday = 30;
    System.assertequals(30, Lastday);
    }

    @isTest static void DateWithin30DaysTest1(){
    Date Date1 = VerifyDate.DateWithin30Days(System.today(),System.today()+2);
    Date Date2 = VerifyDate.DateWithin30Days(System.today(),System.today()+1);
    String Date3 = 'False';
    System.assertequals('False', Date3);
    }

    @isTest static void DateWithin30DaysTest2(){
    Date Date1 = VerifyDate.DateWithin30Days(System.today(),System.today()+1);
    Date Date2 = VerifyDate.DateWithin30Days(System.today(),System.today()+31);
    System.assertequals('False', Date2);
    }

    @isTest static void DateWithin30DaysTest3(){
    Date Date1 = VerifyDate.DateWithin30Days(System.today(),System.today()+1);
    Date Date2 = VerifyDate.DateWithin30Days(System.today(),System.today()+2);
    System.assertequals('True', Date2);
    } 

    @isTest static void SetEndOfMonthDateTest1(){
    Date Date1 = VerifyDate.SetEndOfMonthDate(System.today(),System.today()+1);
    integer Last = 30;
    System.assertequals(30, Last);
    } 

}
4
  • Is it an error, or is "Check This Challenge" telling you that you have not done something correctly? Do you have the exact text of the error?
    – pchittum
    Nov 4, 2015 at 9:26
  • FYI, regarding providing code examples: meta.salesforce.stackexchange.com/questions/1925/…
    – pchittum
    Nov 4, 2015 at 9:37
  • @Peter- it is an error. btw, Im asking about what is the meaning of my error module not visible and what caused that error and Im not asking for the actual answer for the trailhead. Read Nov 5, 2015 at 1:22
  • Not to worry...but you didn't post the error. The actual text of the error and where/when you are seeing it is all key information to answer your question. Otherwise we are guessing. Cheers.
    – pchittum
    Nov 5, 2015 at 10:44

4 Answers 4

1

Late answer but this never seemed to get something definitive. I'd suggest that the error here is caused by the test class being declared private - given that it's being invoked externally I think changing it to public would sort things out.

public class VerifyDateTest{
1
  • Ha, yeah, that's kind of obvious looking at it again. Good catch.
    – Adrian Larson
    Jul 19, 2016 at 1:48
4

If the dateWithin30Days method returns boolean, then a couple of your asserts will never work.

For instance the following:

Date Date2 = VerifyDate.DateWithin30Days(System.today(),System.today()+2);
System.assertequals('True', Date2);

First of all, Date2 is a Date data type.

But 'True' is a String. So if you pass those two to assertEquals you will fail, as two variables of different data types can never be equal.

There is another instance where you are trying to assert, that looks like this:

System.assertequals(System.today(),System.today()+15, Date2);

Here this assert will also always fail. You are comparing the current date to the current date plus 15.

I think maybe you may need some basic help with understanding variables, data types, and using them.

In addition to the Trailhead module, you might benefit from checking out Chapter 3 on sfdc99, which addresses some of these basics. I would also read the docs on using System.assertEquals

Note: as a rule, this community has decided that we will not provide specific code examples to answer Trailhead challenges.

1

Well i can figure out a lot number of errors to your code!

So here we go.

  1. This will never work as System.assertEquals(expected,actual) accepts only 2 parameters and the third parameter if at all there can only be a comment:

    System.assertequals(System.today(),System.today()+15, Date2);
    

    instead of what you wrote it should be like:

    System.assertequals(System.today()+15,Date2);
    
  2. Here you are trying to compare a string with a boolean value because the return type of method is boolean and anything you write in ' ' becomes a string

    System.assertequals('False', Date2);
    

    Instead you should write:

    System.assertequals(False, Date2);
    

Also, I would mention there is mistake of return type in whole block of this function.i can help you with the correct block of code:

so instead of this which is wrong:

 @isTest static void DateWithin30DaysTest1(){
    Date Date1 = VerifyDate.DateWithin30Days(System.today(),System.today()+2);
    Date Date2 = VerifyDate.DateWithin30Days(System.today(),System.today()+1);
    String Date3 = 'False';
    System.assertequals('False', Date3);
    }

try this:

@isTest static void DateWithin30DaysTest1(){
    Boolean Date1 = VerifyDate.DateWithin30Days(System.today()+2,System.today()+1);
    System.assertequals(False, Date1);
    }

this will surely work!

1
  • Your assertion message can be of any type. Point 1 is flat out wrong in that regard.
    – Adrian Larson
    Oct 11, 2017 at 20:25
0

I think you over did this a little bit; you can make this much more simple.

Here is my code for this trailhead:

@isTest private class TestVerifyDate {
    @isTest private static void testWithinThirtyDays(){
        Date tomorrow = Date.today().addDays(1);
        Date result = VerifyDate.CheckDates(Date.today(),tomorrow);
        system.assertEquals(tomorrow, result);
    }  

    @isTest private static void testNotWithinThirtyDays(){
        Date nextMonth = Date.today().addDays(31);
        Date result = VerifyDate.CheckDates(Date.today(),nextMonth);
        system.assertNotEquals(nextMonth, result);
    }  
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .