I’m testing a method which calls -[NSDate date], and uses system time as a reference to do some logic. I need to test if the logic is right on some specific days in the year, but I can’t wait till that day. So can I change the system date programmatically when unit testing?
I’m testing a method which calls -[NSDate date] , and uses system time as
Share
You need to use Mock object and in Objective C you can do it easily with categories by overriding only methods that you need. For example you could use the following category:
and in addition you will need SwizzleClassMethod
and then in your unit test you will be able to use it like this