Friday, May 20, 2016
Post #5 of 6: Good Code Practices for Quality Automation
If MetaAutomation is too much change for right now…
Start with making your code as good as it can be.
I quote Elisabeth Hendrickson in the book on MetaAutomation:
It is tempting for organizations to treat infrastructure code as somehow inferior to production code. 'It's just scripts,' they say. 'We don't need to put seasoned engineers on it.' However what I've seen is that the infrastructure code -- that includes build and CI scripts as well as tests and test frameworks -- is the foundation on which the rest of the code is built. If the infrastructure code is not treated with the same care as production code, then everything is built on a shaky foundation.
Teams should follow the team’s adopted practices for product code where it makes sense, but also consider making some changes for quality automation code:
· Some types of security and performance considerations for product code might be unnecessary in quality automation code, since the latter will never ship outside the team’s control.
· Consider using some structures to help with quality automation-specific code, e.g., to make the actions of driving the product self-documenting in detail. The sample projects on http://MetaAutomation.net show many details on this.
Here too, there are more details in the book on MetaAutomation.
If you have a choice, use a compiled language. The idea that an interpreted language like Python can make QA engineers more productive is an illusion, because not having a compiler on your side can result in runtime failures that a compiler would have caught, causing significant time and cost in following up. An interpreted language lets one write code faster, but that’s not the whole value story. A compiled language like C# will tell you about all sorts of problems immediately, and many others almost immediately and certainly before committing code to a repository. This saves a lot of time.
As a counter-example, I’ve also used Ruby to do quality automation, and among many other shortcomings of this language, it effectively hid problems from me until much later than writing the code, causing significant cost and frustration.
Consider using the same language as the product code, so less information gets lost at the boundary between the product and quality automation code driving the product, the dev role can contribute as needed to quality automation, and the QA role can know more of the product and even contribute to the product as needed.
Personal anecdote: I’ve added XSL code to a product, mainly written in Java, to make an important product web site vastly more testable using both Java and XSL in the quality automation code. This kind of thing is much easier if the languages are common between quality automation code and product code.
Careful to avoid copy-and-paste code; this causes maintenance cost, because the code might have to be updated in multiple places (since the same code is copied multiple places) and if the coder misses one or more of the copies, more wasted time and cost result.
For checks that use a GUI or a web browser, always synchronize to objects or events if possible, rather than sleep. This will help performance and reliability of the checks.
A few more minor points:
· Maximize code reusability and reuse.
· Make symbol names descriptive, so code becomes self-documenting.
· Comment code but only if needed, and always at one level of abstraction above the code itself.
· Always do code reviews! It’s an opportunity to learn from each other and raise code quality and uniformity across the team.
This page is #5 in a series of six, with the original post here.