You need to sign in to do that
Don't have an account?
Holly Havelka 17
Help With DateTime Test Class Failing
Hello all,
Having an issue with my first test class failing. Need help on setting a specific time in my mock data for the test to not fail.
Here is my class:
Having an issue with my first test class failing. Need help on setting a specific time in my mock data for the test to not fail.
Here is my class:
public class DateHelper { public static Long GetTimeStampFromDate(Date inputDate) { Long timeStamp = 0; DateTime dt; if (inputDate == null) return timeStamp; dt = Datetime.newInstance( inputDate.year(), inputDate.month(), inputDate.day() ); timeStamp = dt.getTime(); return timeStamp; } }Here is my test class:
@isTest public class DateHelperTests { @isTest static void GivenAValidDateInput_GetTimeStampFromDate_ShouldReturnValidTimeStamp() { //Arrange Date inputDate = Date.newInstance(2019, 10, 21); Long expectedResult = long.valueOf('1571630400000'); //Act Long actualResult = DateHelper.GetTimeStampFromDate(inputDate); System.assert(expectedResult == actualResult); } @isTest static void GivenNullDateInput_GetTimeStampFromDate_ShouldReturnZero() { //Arrange Long expectedResult = 0; //Act Long actualResult = DateHelper.GetTimeStampFromDate(null); System.assert(expectedResult == actualResult); } }Any help is much appreciated!
All Answers