June 6, 2021
Top 20 Best Practices For Writing Better Automation Test Code
Programming Language Wise:
- Follow Programming Language Guidelines( method name-getPayload(), class name- APIEndpoints, package name-com.testingsumo.backend.tests, variable name-authToken)
- Follow Oops Concepts Wherever Possible- Abstraction(base classes), Inheritance(multiple implementations of same things/multiple inheritances), Polymorphism(many forms with something different), Data Hiding(hide unnecessary/sensitive info), Encapsulation(Bind small entities into a single large entity)
- Reduce code duplication (think before writing new code, can I use/make changes in existing code?)
- Increase code reusability
- Make your code generic wherever possible
- Leave no hardcoded data in source code
- Keep your static data outside the source code
- Keep your dynamic data dynamic in test code (fetch it from DB queries or scripts)
- Test your code properly, use IDE options such as call hierarchy or show usage to test your changes end 2 end
Framework and Debugging Wise
- Use Extensive logging- everything which is part of source code should be analyzed from logs without looking at the source code
- Generate and save failure proofs outside the src code- videos/data/screenshots/logs
- Focus on making your code scalable and faster without compromising the code quality
- Your code should be platform and system independent
- Use as many assertions as possible focus on automated testing rather than automation
- Leave no hardcoded data in source code
- Always think for the future, separate out tech dependencies so that migration to new tech is easy in case it is needed
- Keep your tests independent for better results in multithreading unless they are related (for example publisher-subscriber related tests)
- Use Proper Documentation
- Create code that can be easily read and modified by others
If you want to understand these best practices in a detailed manner with more depth and examples, please view the below video tutorials here-
If you have any best practices to suggest or have any feedback for us, please comment below.