test automation best practices – TestAutomasi Blog https://testautomasi.com/blog A blog On Test Automation Case Studies & Automation tools Sun, 02 Jul 2023 22:33:28 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 Top 20 Best Practices For Writing Better Automation Test Code https://testautomasi.com/blog/2021/06/06/top-20-best-practices-for-writing-better-automation-test-code/ Sun, 06 Jun 2021 12:03:06 +0000 https://testautomasi.com/blog/?p=165 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.

]]>