10 Rules for Writing Automated Tests

Page 1

AUTOMATION TESTING Automated tests need to be written in a logical, specific and structured manner so that eventually the testing process becomes easier, faster and more efficient. Automation testers can improve their productivity if they stringently follow a few key rules for writing effective automated tests.

TEN RULES FOR WRITING AUTOMATED TESTS: THE CONDITIONS BEING OCCURRED SHOULD BE REDUCED: Conditions (if-statements) should be as few as possible for a test. If there are many conditions then it becomes unpredictable, which means the exact state cannot be known.

SCRUTINIZE THE ABSTRACTIONS If a test mostly consists of user interactions, such as set-text actions and clicks, then there is something that is going wrong. If low-level frameworks such as selenium are being used, then the business logic is separated from the low-level implementation that is recommended by Page Object Design Pattern.

ISOLATED AND INDEPENDENT TESTS NEED TO BE WRITTEN: A significant element of test authoring is creating independent, self-contained flows. Through this, the tests can run in high parallelism, which is considered to be crucial for the test suites to scale.

IMPROVING STABILITY One of the main sources of flaky tests is to sleep with random duration. Almost all the apps are considered to be asynchronous in nature. There are specific cases where a human is not able to know whether the page is ready or not and when the next action should be performed.

OBSERVE THE STATE OF THE TESTS The same set of steps is continuously repeated by automated tests, the same initial state is where they should always start from. When the automated tests are being run, the most common maintenance issues are making sure that the initial state is properly integrated.

ARRANGE ACCORDINGLY There are thousands of scenarios that are included in most of the apps. The correctness and functionality that are being tested are merely one step of the way for meeting user expectations and shipping high-quality software.

OPTIMAL USAGE OF SIMPLE STEPS: Real user scenarios are emulated by complex tests. The test should be composed from simple test parts, instead of the entire scenario being recorded directly. As all the simple actions are tested already in the simple tests, the complex tests should fail on integration issues only.

THE VALUE OF ADDING VALIDATIONS At the end of the test, validations are used to signal the test in a failed/passed state. At points of major changes, validations can be added as a checkpoint to stop the test if a specific action has been failed. Validations will run till it has reached a timeout.

DEVELOP STRUCTURED TESTS It is easier to create and maintain single purpose tests and they will also run faster compared to complex and longer ones. If a particular feature that is being tested is broken or one of its dependencies, then there are chances of failing.

REDUCE, RECYCLE, REUSE The user scenarios can be broken down into single purpose, simple and almost atomic flows. A good naming convention should be defined.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.