Test Automation Design Patterns

Learn about the different types of test automation design patterns.

As I emphasized earlier, test automation is engineering, and thus, design patterns and best practices apply to this area as well. By learning and employing design patterns, you will enjoy their typical benefits: clean and efficient code, leveraging knowledge instead of reinventing it, a shared vocabulary, and so on. Due to these positive outcomes, every automation engineer must know several fundamental design patterns that I will cover next.

Crux of test case patterns

A design pattern often has a shape of abstraction that it represents. For example, a repository pattern looks like a storage of things. Likewise, if I wanted to describe a test case pattern, in my mind, it would look like a scenario that this test case covers. This simple idea is the crux of the two models that I cover next.

Gherkin test case pattern

If your team employs Gherkin language when formulating scenarios, perhaps it makes sense to model your test cases around this dialect too.

For instance, a Gherkin scenario text might look like this:

How can we model a test case pattern to mimic such a scenario? Easy! Imagine an object that has five methods on it, each implementing a corresponding step of the scenario. This construct is a Gherkin Test Case design pattern.

To execute code from the Gherkin test case object, you can utilize one of the specialized frameworks that parse Gherkin text and map your object’s methods to scenario steps (e.g., see Xunit.Gherkin.Quick). Such structures help you implement the described pattern by letting you focus on test automation instead of language parsing routines.

Scenario object pattern

If you use a popular Gherkin language for writing scenarios, perhaps the Gherkin Test Case pattern is your best bet. However, more often than not, test scenarios do not rely on Gherkin, and hence the described design does not apply. Instead, when writing test cases, we often end up structuring them as our tools or conventions govern.

For instance, if you use Microsoft Test Management (MTM) system for ...