Why should you refactor tests?

Why should you refactor tests?

Refactoring can reduce maintenance by breaking down test automation code into smaller, more reusable pieces. And it can do the same for automated test cases. More reuse in your codebase means fewer places to fix problems. It also means less time to search for defects in your test automation code.

What is a refactoring test?

With unit testing in place, refactoring is then an iterative cycle of making a small program transformation, testing it to ensure correctness, and making another small transformation. If at any point a test fails, the last small change is undone and repeated in a different way.

When do you start a refactor in coding?

At “Coding” step we are assumed to write code as simple as possible, just to fix a failing test. We should not write complex code until it is really required. The next step is Refactor. Should we refactor just written code? I think there is no real sence, as we should be happy with code as far as tests are passing.

When to write failing test, code, or refactor?

“Write failing Test” -> “Code/Refactor” -> “Write failing Test” + “External factor (like bad performance)” -> “Refactor”. TDD is a great tool to keep you on track/on task. The problem with: you propose, is it can easily become: which is what you want to avoid.

When to start a refactoring in a project?

When you are doing something similar for the second time, cringe at having to repeat but do the same thing anyway. When you are doing something for the third time, start refactoring. Refactoring helps you understand other people’s code. If you have to deal with someone else’s dirty code, try to refactor it first.

When is it a good time to refactor?

There is no bad time to refactor, because you are going to run your tests again to prove you didn’t break anything before committing the change. Its only bad if you’re only ever refactoring and never adding new functionality as required by the current project.