unit testing - System.Today() and System.Now() in test class -


how can mockup system.today() , system.now() in test class further logic?

i remember sf having limitation while not sure if came new.

depending on code doing, possible modify code pull logic involved separate method pass in system.today() or system.now(). @ point can test component , pass in date/datetime of choosing.

for example, if code following testability:

system.debug(system.now().adddays(2)); 

changes to:

public static datetime adddays(datetime d, integer i) {     return d.adddays(i); }  system.debug(adddays(system.now(), 2)); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -