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

Viewed 605

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 overkill to what I was trying to achieve.

1 Answers
Related