Today we will answer this question:
Q: Clean code in automation, Is it really necessary?
A: Well… why not? let’s speak about the advantages of clean code and clean code in automation especially:
Let’s start by defining what is clean code exactly?
Clean code is a reader-focused development style that produces software that’s easy to write, read and maintain. Developers are often tempted to consider their work complete when the application operates as expected. But we’re not merely writing code for computer consumption.
“Programming is the art of telling another human what one wants the computer to do.” – Donald Knuth
So, Why clean code:
1. Your code is your pride! Your test is running now, but is the task really complete? What will happen tomorrow when the test fails? Do you know how to fix the test by reading the code only? without debugging? Clean code is a way to write code that you can understand later, be proud of the text you write because this is apart of writing to humans and not just to machines.
2. Well… let’s face it – writing clean code makes your life easier! Of course, it doesn’t make it easier right away, but it pays itself the first time you need to rewrite a test or to add a feature when all your methods are small and posses the single responsibility principle! now its actually easier to add features to your test!
3. Because as automation engineers we need to read a lot of logs! We woke up in the morning and 17 out of our 100 tests failed… but why? do I know where? was it a specific bug? part of writing clean code means writing good methods names that are readable, so, if we will follow the stack trace we will find our error easily without breaking a sweat!
4. Because you are a professional! And as a professional, you want to continue and develop your skills and not get stuck in the back!
5. Because even more than software, automation is read over and over again! As mentioned before a clean code is written for humans and not for machines! automation is being read, changed and modified even more than the software code, do you really think you will remember what was variable ‘x’ a month from now when you are reading your test and trying to modify it?