Maintaining the test scripts in small modules helps us in maintenance by providing the scalability. Take, for example, using Cucumber BDD, where features can be split into small, manageable pieces.
For example, consider a finance application where user is taking these steps:
- Login into the app
- Apply for loan
- Check personal information
- Check credit score
- Check previous loan history
So, instead of creating a single test script to first — apply for loan, then check personal info and finally check credit score, it’s much more beneficial to write separate scripts for each module. This modular approach brings flexibility to handle changes efficiently. For instance, if there’s a modification in the personal information module, there’s no need to execute the loan application and credit score checks. This ensures better maintenance and flexibility.
Follow clean coding standards. These practices make it easier for both current and future team members to understand and update the code.
Here are some specific ways in which clean code can help with test maintenance:
- Use descriptive names for variables and functions. This makes it easier to understand what the code is doing, which makes it easier to identify changes that need to be made to the tests.
- Use comments to explain what the code is doing. This can be especially helpful for complex code or code that is not well-organized.
- Break the code into small, manageable chunks. This makes it easier to understand and modify the code, which makes it easier to update the tests.
- Use consistent formatting. This makes the code easier to read and understand, which makes it easier to identify changes that need to be made to the tests.
- Avoid using magic numbers. Magic numbers are numbers that are used in the code without being explained. This can make it difficult to understand what the code is doing, which can make it difficult to identify changes that need to be made to the tests.
- Avoid using global variables. Global variables are variables that are accessible from anywhere in the code. This can make it difficult to track changes to the code, which can make it difficult to update the tests.
Here’s a casual exchange with our CTO on coding standards, clean code, technical debt etc…