Site icon SmartQA

Design for testability

In this smartbits, Girish Elchuri outlines about Design for testability.

Another practice that I follow is, during the testing times, the code is made to behave differently, though I am not altering the functionality. For example, in a particular workflow, I add a mobile number or an email id and I validate them later. There may be certain functionalities that would be possible only when you verify the mobile number and email id. These are the mundane things for which you cannot do the test automation. 

So what we do internally is when we are in the test mode and as soon as the mobile number is added or the email is added, we treat them as verified, we put that flag, so that we can do further testing in a much more efficient manner. That is just an example of how you can make the product behave differently for testability which is a much more efficient way of doing it, this is the first aspect.

Secondly, in a workflow-based product, you do certain things and for the third step of the workflow, you might need some information that is generated in the first and second steps. Normally, this will be visible to the user on the GUI but then on GUI-less test automation, it becomes difficult. So what we do is, in the testing mode, we actually generate this data as a file and then using the data which is generated as a file, we do the next steps in the workflow. This is another way that we make the code behave differently in a testing mode.

Thirdly, in a small percentage of cases, when the test is being run for subsequent steps, the code itself generates the test automation scripts. So what I do is instead of just outputting the data, I output a callable script call into the file and in the end, I just execute that file.

Since all these behaviors occur during testing, we can have a flag there saying “I am testing” and then what we can do additionally is make sure that these things are not run in production mode. These are some additional checks that we are doing. Again, that is where I see a developer helping the testing folks by putting this additional code to facilitate the testing.