on-internet
← Community

How to test time-based functionality without implementing it within the test?

Stack Overflow ·

I'm trying out TDD on some side project and already encountered this a couple of times. As an example, my program needs to take a number X, and find out the date string that was X days ago, in order to perform certain date-based queries. So I figured I need a test that validates the date computation is correct. But, since the test depends on the current date, how can create such a test? I can have the test method implement this exact functionality by itself, but that would just make it redundant... Edit: I've seen Setting time and date in JUnit test fixture but the answers there seem quite an

Comments

Sign in or sign up to comment and upvote.

No comments yet.