Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 2
    You can't. That's why people are so obsessed about autowiring and dependency injection: if your time provider or your database handler were non-hardwired, you could easily mock it for testing without changing the source. As it is, you have to essentially wait until Monday to run the test, which is a Really Bad Thing. Commented Mar 18, 2017 at 21:26
  • Your comment seems to be the answer. I have read a little about dependency injection, but it seems to be used for various things and I am having trouble relating the specifics to what I am trying to do (unit-testing). I could not find much on autowiring (only related to Spring). Can you post an answer explaining these two concepts with some good examples of how they can be used to unit-test... or direct me to a SO question that does. My terminology is weak, so searches are coming up blank. Commented Mar 18, 2017 at 21:50
  • This question has some information but indicates it is not necessary for unit-testing. Not sure how this could be in the example I gave. Commented Mar 18, 2017 at 21:52
  • Depends on the language I guess. In c#, it is certainly possible using fakes. See this answer for an example of swapping out DateTime.Now with your own shim. Commented Mar 18, 2017 at 23:49