You need to sign in to do that
Don't have an account?
Nishit Mistryyy
Test class for date
I have a code where I am getting the year, month and date from the date which is passed as a string, i need to write the test class for it.
Here is the class:
public class DateHelper {
/*
Integer year_;
Integer month_;
Integer day_;
*/
public static datetime Get_Date_FromYYYYMMDD(String DateString)
{
Integer year = integer.valueof(DateString.substring(0, 4));
Integer month = integer.valueof(DateString.substring(5, 7));
Integer day = integer.valueof(DateString.substring(8, 10));
return Date.newInstance(year, month, day);
}
/*
public date GetFromYYYYMMDD_P
{
get
{
return Date.today();
}
}*/
}
Here is the class:
public class DateHelper {
/*
Integer year_;
Integer month_;
Integer day_;
*/
public static datetime Get_Date_FromYYYYMMDD(String DateString)
{
Integer year = integer.valueof(DateString.substring(0, 4));
Integer month = integer.valueof(DateString.substring(5, 7));
Integer day = integer.valueof(DateString.substring(8, 10));
return Date.newInstance(year, month, day);
}
/*
public date GetFromYYYYMMDD_P
{
get
{
return Date.today();
}
}*/
}
I hope it is just to change Date String to Datetime.
Please use below test class. It covers 100% of code.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,