An introduction to Serenity BDD
To get the most out of Serenity BDD, it is useful to understand some of the basic Serenity BDD behind Behaviour Driven Development and Automated Acceptance Testing. Serenity BDD is commonly used for both Automated Acceptance Tests and Regression Tests, and the principles discussed here apply, with minor variations, to both.
Behaviour Driven Development or BDD, is a development approach where team members explore, and build a shared understanding of application requirements through conversations around examples. In Agile teams practicing BDD, this is often done before or early on in a sprint, in a special meeting sometimes called "the three amigos" or "the three-way handshake", where (at least) a BA (Business Analyst, Product Owner/Manager), a developer and a tester get together to work through examples from the acceptance criteria. The examples being discussed are concrete illustrations of how the system should work, or how a user might use a feature. These examples help provoke discussion, uncovering assumptions and omissions that would have otherwise lead the development team into error further down the track.
Let’s look at an example. Suppose we are building a simple todo-list application. In Agile terms, the corresponding user story might look like this:
In order to avoid having to remember things that need doing As a forgetful person I want to be able to record what I need to do in a place where I won't forget about them
If we were implementing this story, we would typically define a set of acceptance criteria to flesh out and understand the requirements. For example, we might have the following criteria in our list of acceptance criteria:
Add an item to an empty list
Add an item to an existing list
Complete an item
If we were using a Behaviour-Driven-Development approach, we might express these requirements in a more formal form, like the following:
Scenario: Adding an item to a list with other items in Cucumber Given that Jane has a todo list containing Walk the dog, Put out the garbage When adds a todo item called: Buy some milk Then her todo list should contain Walk the dog,Put out the garbage,Buy some milk
This Given When Then format is widely used for acceptance tests in Agile projects.
Note how this scenario is deliberately pitched at a fairly high level, in business terms, describing the business motivations behind the feature without committing to a particular implementation.
When a tester or a developer automates and executes this scenario, or a BA reviews the results, they will often want to see a bit more detail. For example, the tester will want to see how the screens played out (if it’s a web test), what test data was used and so on. And the BA might want to see what the screens look like for each step.
Serenity helps you see these details in its test reports. Here’s a simple example of one of these:
Notice how it lets you see the high-level view of the test, but also lets you step into the details and see a blow-by-blow account of the test execution. There is something for everyone!
But Serenity doesn’t stop with just test reports. Serenity BDD also gives you a broader picture, helping you see where individual scenarios fit into the overall set of product requirements. It helps you see not only the current state of the tests, but also what requirements have been (and have not been) tested (see An aggregate report generated by Serenity).
Serenity BDD is also commonly used for automated Regression Tests. Whereas BDD Acceptance Tests are defined very early on in the piece, before development starts, Regression Tests involve an existing system. Other than that, the steps involved in defining and automating the tests are very similar.
When it comes to implementing the tests themselves, Serenity BDD also provides many features that make it easier, faster and cleaner to write clear, maintainable tests. This is particularly true for automated web tests using WebDriver, but Serenity BDD also caters for non-web tests as well, such as tests that exercise REST APIs. Serenity BDD plays well with JUnit as well as more specialised BDD frameworks such as Cucumber and JBehave.
In the coming sections, we will look at how to do all of this, and more, with Serenity BDD.