Hey Dudes,
Most of us daily writes number of scripts and running them in batches for 100's of times. But we never think about the maintainability of the scripts.
It happens because most of the times, we wont get sufficient time because of build release schedules.
After developing a script, surely it will goes to a maintenance phase, but as per my experience i feel that script maintenance time does not exceed the script development time.
But here is a basic things(check lists) which we need to consider at script development to make it more easy to understand and maintainable.
This check list not only intended for the automation developer and also useful for the script reviewer.
Only script developer adherence to this check list not only enough,strict reviews should be happened with the experienced automation people and must educate the developers about the advantages of following the predefined guidelines.
Here are the some guidelines which i feel will be useful for the scripts developers:1. Provide the script details in the header which conveys the purpose and author details.
2. Identify the precondition to be met prior to the script initiation.
3. Identify the assistance of third party tools(if required) to fulfill the functionality.
4. Provide detailed log messages for every functional point verification.
5. Verify the alternatives before going to use the check points, because it attracts maintenance.
6. Provide the appropriate comments for each block of code, to understands the code at later point of time and also helpful for others to understand our scripts.
7. Usage of appropriate error handling mechanisms either through programming language or built in tool feature to handle unexpected windows and run time errors.
8.Declare each and every variable at the beginning of the script and relevant comment about the type of data to be stored.
9. Release the resources acquired during the script execution time, for e.g when we set any object it occupies some memory, if it is not released after usage, the memory gets wasted.
10. Restore the application under test to the base state at the end of every script, such that it should not other scripts.
11. Clean the unnecessary files which are created during the execution time to store some intermediate results(like text files, csv files etc)
12. Identify the code components which can be used more often, or used repeatedly and make it as reusable.
13. If more than one developer working on automating the same features, while developing the reusable components make room for other to extend your reusable function, such that code redundancy can be reduced.
14. Never use any hard coded stuff in the scripts like paths, values etc. which are major road blocks in the maintenance, parameterize these values from a external source like configuration files.
Guidelines for Script Reviewer:A script reviewer can use all the above mentioned points and including the below for the better maintainability.
1. Execute the script at least once.
2. Verify the conditional statements for false positives validation.
3. Verify the log messages and comments and header details most of the developers misses because of copy paste activity.
4. Verify the loops such that cant be executed for infinity
5. Verify the script doesn't break or produce any unexpected behavior when provided with different sets of data.