| The point of "just writing enough to make the test pass" is to get you to the point where you have working software (proven by the test, even if the code is "bad") This is the _only_ point where you can safely refactor, if your tests are failing how do you know you haven't broken something? So long as you keep things "green" you know you're ok > The danger seems to be when you have to walk away from some code and you or whoever picks up your code doesn't know what you were up to. Just don't do this. You're not "done" with the TDD cycle until you make it pass and have refactored. I reflect this in my git usage too, roughly it goes - Write a test
-> Make it pass
-> git commit -am "made it do something"
-> refactor
-> run tests (if i get in a mess, revert back to safety and try again)
-> git add .
-> git commit --amend --no-edit > It seems "safer" to write tests that are going to stay broken until every little corner of everything works properly, even though this is less iterative. The problem with this is how do you safely refactor when you have potentially dozens of tests failing? A big point of this approach is it makes refactoring a continuous process and makes it easier because you have tests proving you haven't accidentally changed behaviour. |