The first principle in test automation is that tests are first class citizens of your project. This is important in a couple of ways. Firstly in terms of preventing decay in test code. We’ve already spoken about how important it is to treat your test code as if it were real production code.
Test code is at least as hard to write and maintain and debug as production code, so you need to treat it with the same love and care and respect. That means refactoring relentlessly to make that your code is readable and expresses intent clearly and is maintainable. Don’t repeat yourself. Anywhere you have code that is duplicated across tests find ways to remove that duplication, but again, not at the expense of readability. Of course, it’s important not to repeat yourself. That is vital to creating well-maintained code.