by Nataliia Vasylyna | June 26, 2015 10:00 am
Note: the article was updated in September 2020.
The term ‘Refactoring’ stands for the process of code cleanup and redesign aimed to improve its internal structure without altering the functionality. Refactoring reduces code complexity, cuts off redundancies, and cuts down on unnecessary loops. All the manipulations are performed on a code already deployed and used in production.
Despite the popular misconception, refactoring is not only for software developers. Test code refactoring involves changes in test code that increase its maintainability without adding or removing test cases.
Refactoring is a valuable practice in testing. Why? It naturally makes everything better.
Refactoring test code differs from refactoring production code in a particular set of bad smells involved and, therefore, it requires test-specific refactorings.
There are several reasons behind the need for a particular module or piece of code to get refactored, including code smells, technical debt, and implementation of agile methodology.
N.B. There are numerous code smells that are specific to test code. The list includes undesirable duplications, test methods in production code, assertions in a test method that have no explanation, resource interference, use of external resources, test code that makes optimistic assumptions about the existence or state of external resources, etc.
The golden rule of test code refactoring states that tests should work as intended afterward. Other principles involve simplifying tests if possible, detecting and removing code smells, as well as applying suitable refactoring methods.
There are five test code refactorings test automation engineers can implement right away:
Test code refactoring is an important technique that involves restructuring an existing body of code to make it cleaner and, therefore, allows increasing the productivity of test automation engineers. It also may reveal missing test cases and even helps in improving the production code by indicating the presence of code smells.
Source URL: https://blog.qatestlab.com/2015/06/26/automated-tests-refactoring/
Copyright ©2021 QATestLab Blog unless otherwise noted.