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.

6
  • 4
    It's a human thing: you have to resist the urge to cheat. There is nothing more to it. You could add more tests and write more test code than code to test, but if you don't have that luxury than you'll need to just resist. There are MANY places in coding where we have to resist the urge to hack or cheat, because we know that, while it might work today, it won't work later. Commented Nov 25, 2010 at 16:17
  • 10
    Surely, in TDD, doing it the other way around is cheating - i.e. return 120 is the proper way. I find it quite hard to make myself do that, and not race ahead and start writing the factorial calculation. Commented Nov 25, 2010 at 16:32
  • 2
    I would consider this a cheat, only because it may pass the test but it does not add any true functionality or get you closer to a final solution to the problem at hand. Commented Nov 25, 2010 at 19:06
  • 4
    If it turns out that client code code only ever passes in a 5, returning 120 is not just a non-cheat, but is actually a legitimate solution. Commented Nov 26, 2010 at 17:41
  • I agree with @PaulButcher - in fact, a lot of unit testing examples in texts and articles would take this approach. Commented Aug 15, 2011 at 1:31