What is TCR?

Test && Commit || Revert (test and commit or revert for the non-technically inclined readers out there) which will be referred to as TCR from this point forward is another extreme idea of Kent Beck’s (just like TDD). The concept is simple. Every time you write some code, you run your tests. If the tests pass, you immediately commit the code. If it fails, you immediately revert your code.

Benefits of TCR

TCR has two major benefits. You have a great commit history (of all passing tests), and it forces you to write small amounts of code at a time. This means that you are taking complex problems and breaking them down to much smaller ones. It also means you are never going to run into an issue of your code being in a broken state, where you don’t know when the last time it worked was because you’ve forgotten to commit it. Finally, it encourages you to not do a lot of code all at once, instead making every bit of code you write more purposeful.

Difference to TDD

In TDD, you follow a red, green, blue pattern. First you write a test that fails (red), then you write some code to make it pass (green), finally you refactor the code.

In TCR you start by writing some code. Then you write the test to be accurate to the way you believe the code behaves. Finally, you refactor after you are sure that the code is doing what you think the code is doing.

Final Thoughts

While TCR seems to enforce good coding habits, it seems that it’s harder to get 100 percent test coverage in TCR compared to how easy it is to get in TDD. So for now I think I’ll stick to TDD. But it doesn’t seem like a bad thing to dip my toes into every once in a while.