I need to create a test to verify my NewBusinessDateTime.calculate(Integer hoursToAdd) works. The sudo code of what calculate() does is:

IF currentDateTime.addHours(hoursToAdd) IS WITHIN BUSINESS HOURS
RETURN currentDateTime.addHours(hoursToAdd)

RETURN nextDateTimeBusinessIsOpenRightWhenBusinessOpens

The business hours are

//  M-F 8 AM - 8 PM
//  SAT 10 AM - 4 PM
//  SUN Closed

What would be the most effective way to write a test to cover every possible time, 24 hours a day, 7 days week? Or is that desire too excessive? Unfortunately in my production code, I'm getting reports from users saying what NewBusinessDateTime.calculate(Integer hoursToAdd) is outputting is sometimes in the past, too far into the future, and other unexpected behavior.

1 Answer 1


You can use some Boundary Value Analysis to filter out the list of test cases. You would probably do a better risk analysis than anyone else in this case, but I can imagine the following as the riskiest test cases:

Monday 8 AM Monday 8 AM +- 1s

Monday 8 PM Monday 8 PM +- 1s

Saturday 10 AM Saturday 10 AM +- 1 s

Saturday 4 PM Saturday 4 PM +- 1s

Some assumptions in this list:

  • You can update the time at the second level. If it comes only at minutes level (type checking), you can change the variation to 1 minute;
  • It assumes that all week days are more or less the same case, therefore, testing only Monday is ok;
  • It assumes Saturday may cause some unique problems; if not, testing only Monday is ok.


  • Be sure addHours is a pure function. If not, when you call it twice (on the if and inside it), you would be adding the time twice.

  • Be sure that nextDateTimeBusinessIsOpenRightWhenBusinessOpens is working properly. IMO, it should receive currentDateTime - a bug may be hidden there if it depends on another form of getting the current date.

  • Your Additionally section seems more relevant/interesting considering the problem! @joão-farias Jan 30, 2019 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.