What is a framework?
According to Wikipedia, a framework is an abstraction in which software providing generic functionality can be selectively changed by additional user-written code, thus providing application-specific software . It isn’t the easiest definition to digest, and one can usually struggle to actually tell a difference between framework and library. The key difference between framework and library, however, is who calls what. Long story short, when you use library, you call library’s code. In comparison, when you use a framework, it calls your code.
Test automation frameworks by no means different. In general, a test automation framework is something that allows you to implement application-specific test automation solution by writing and injecting some additional code. Surprisingly, in test automation community by framework people often mean any test automation solution that happened to have any decent structure and design. Wikipedia as well supports this opinion .
The most common “architecture type” of a test automation solutions I’ve seen was something that could be described as a “big ball of mud“. And, in some cases, it performs just great- such things don’t take ages to implement, quite easy to support for some shot period of time if you have limited amount of tests.
The really challenging question is why and when you need a real test automation framework and when you may go with plain “big ball of mud” test solution.
Start with question”why?”
All in all, test frameworks designed to address following issues:
The simpler the test on the top level is, the easier it is to create, understand, communicate and maintain.
2. Test maintenance cost
Test automation isn’t a thing that goes for granted, it has a price. One of the most painful prices for test automation is a maintenance cost. Well-designed framework should simplify maintenance.
3. Test execution time
Time is a money. Time to get a feedback from automated tests is also crucial – one wouldn’t like to wait for several hours just in order to check that his commit wasn’t wrong.
Testing is about not finding bugs or accepting stories. Well, not exactly. What testing is really about – is providing an information. Test solution that has simple, maintainable tests, easy to maintain and enhance may be just thrown away if it produces shity reports that difficult to understand by non-technical stakeholders.
All things considered, if you don’t plan to have hundreds of complex tests scenarios, your tests are fast and you’re happy with built-in Xunit framework you may not need a test automation framework at all. The rule of thumb – the lower test level you’re interested in, the less complex should test automation solution be. In most cases, you don’t need a framework for unit or integration tests, however you may want one for acceptance tests.
Disregard of what test level you’re interested in, there’re some typical framework architectures that can be utilized. Most interestingly, framework architecture isn’t affected by test-automation approach applied (keyword-driven, BDD, plain code or whatever), because those approaches affects only some layers (most prominently test layers) and don’t touch others. Lets then take a look at the most know test framework architecture.
While test automation framework are designed to address issues outlined above, it is usually isn’t overly complex software system. The most commonly known architecture pattern known as Layered Architecture is often used as a base for test automation framework architecture.
Components withing the layered architecture are organized into horizontal layers, and each layer of the architecture has specific role and responsibility in the application. Components within a specific layer are supposed to deal only with logic that corresponds to that layers .
Three-layered automation framework
The most known and widely used architecture for software test automation solutions is a three-layered architecture, in which solution is divided into three logical horizontal layers, usually test layer, business-layer and core layer.
In such architecture, test layer typically contains test scenarios itself, either in programming language or in any other form (like BDD feature files).
Business layer provides system under test (SuT) specific actions. For example, if we’re talking about online shopping, such actions may be log in, add something to cart, e.t.c.
Core layer is where real framework (who calls your code) really lives, and it deals with test orchestration, reporting and usually also provides low-level API to communicate with tested application, like web-service facades, Selenium Web Driver wrappers, e.t.c.
In a BDD inspired framework, test layer will typically contain feature files, business layer will contain steps definitions, while core layer contains BDD- framework configuration and core component. For a data-driven framework, test layer will contain data files and, business layer will contain mid-level application specific abstractions.
Four-Five layered automation framework
In case you may need something more complex, there are several options to enhance framework architecture. One of the options you may choose, is to extract validation code into separate level (or module, to be precise), which will be used by business layer, while core layer may provide interface or orchestration for validation.
In case you’re building hybrid framework, you may need separate layer for a data, so your test layer will have data and non-data tests. All this will add complexity to a core layer, so also logical may be to separate it into several sub-levels at some point.
Plug-able test automation framework
In case you application is even more complex, you may want different validation for different environments, or different ways to communicate with application for same tests (for example for testing desktop and mobile versions of the web-page). While it is possible to address this by creating sub-modules in core or validation layers, there’s also neat way to do this completely opaque to the rest of the system. The idea is to use dependency injection and provide plug-able modules for validation and test-application interfacing.
The idea is essentially the same as in previous framework architecture, with only difference – validation and facades implements provided interface, which is used by business layer and concrete implementation is typically injected without other layers knowledge about what was really injected.
While it is often tempting either to pick-up the most complex architecture (just in case) or the simplest thing (faster to implement), it is often wise to provide some initial investigation of what you may need based, for example, on product vision or expected length of life.
Provided architectures are by no means a standards, they are just examples, and you may implement plug-able three-layered thing, or even identify 7 different hierarchical layers. You may want some event-driven thing for testing of asynchronous workflow.
There are several typical highlights:
1)Try to make tests as simple, short and atomic as possible. Ideally, test should tell what is being done, not how it is done and test only one specific thing. Typically, cost of complex test support outweighs benefits of having such test.
2)Business layer should provide action implementation (how something is done) using interfaces provided by core layer
3)Validation layer should provide action implementation using interfaces provided either by core or business layer
4)Core layer is the framework itself, and may have complex architecture on its own. It’s responsibility is to provide interfaces for upper layer, provide orchestration for test run and reporting. It also often provides low-level implementation for interfaces exposed to upper layers.
All-in-all, there’s no right for all architecture, so you may suggest any other ways to separate test logic. Provided examples are just a place to start. Which is important, is that one should be able outline the architecture of the solution he is working on and guess if it fits to the project or application. My personal advice would be – stick to the simplest architecture that fits your immediate needs but try to leave options for you in case of need.
 Mark Richards, Software Architecture Patterns. O’Reilly Media, 2015