Requirements and tests are just two sides of the same coin. You can’t have a user story or requirement without an acceptance criteria (test). These two meld into executable specification.
Using gherkin syntax (given,when,then) we can represent requirements using examples and create specifications by example.
As a potential customer I want to collect books in a shopping cart So that I can order several books at once.
◊ Books can be added to the shopping basket
◊ Books can be removed from the shopping basket
◊ Shopping basket is initially empty
◊ The same book can be added multiple times to the shopping basket
Focusing on the 1st acceptance criteria, we can then write this requirement using specification by example:
As a potential customer I want to collect books in a shopping cart So that I can order several books at once.
◊ Books can be added to the shopping basket
– Given my shopping basket is empty
– When I add the book “Harry Potter” to my shopping basket
– Then my shopping basket should contain 1 copy of “Harry Potter”
The above statement is actually an automated test that run and return a pass or fail result. It is written in a way that a business person can understand and it represent a functional requirement.
If I want to test cart counts or cart content or cart total discounts, I can hook this test directly to where the logic is and avoid exercising all the unnecessary steps to get to the cart.
Many teams use this technique with a tool like selenium which executes these tests via the UI. Again, this is unnecessary for exhaustive functional testing. Selinuim test are long running test and are hard to maintain, so we just need a few of them to make sure everything is connected and works nicely together, but for functional tests, we should run these spec by example tests as close as possible to where the code is.
These specifications by example become “green” documents. Instead of having long spreadsheets of test cases with expected results, actual results and pass/fail, we instead represent our requirements as specifications by example and use them as automated tests. They help the team think and collaborate with the customer, and they communicate what the application really does. They always have to stay current and will not rot. If the requirements change and we update the example, the code will fail so we need to fix the code. If we happen to change the code without updating the example (test), the code will fail and we need to update the example (test). So it ensures our documentation and our code are always in sync.
Also check out the entire Agile Testing series:
- 4 Typical Transitions Teams Go Through When They First Start Adopting Scrum
- The Most Common Misunderstanding of Agile Software Development
- What are the Different Types of Tests?
- What is The Agile Testing Quadrant?
- Which Tests Should We Automate?
- How Many Tests Are Enough?
- What is The Testing Pyramid?
- When Do We Start Testing in Scrum?
- Who Is Responsible for Testing in Scrum?
- What is Test Driven Development (TDD)?
- Why You Shouldn’t Do Functional Testing From the UI?
- What are Executable Specifications or Specifications by Example?
- What is Acceptance Test Driven Development (ATTD)?
- Testing Green Field Applications vs. Legacy Applications
- What is Exploratory Testing?
- Top 8 Things to Consider for Your Agile Testing Strategy
- Agile Testing – Testing from Day 1 Presentation