Skip to content

Agile Testing - Methods

In modern Agile Testing, methods are deeply rooted in the ‘Test Early’ and ‘Continuous Testing’ principles. The focus is on preventing defects through collaborative practices where test cases, or more broadly, test scenarios and acceptance criteria, are defined before or in parallel with code development. This ensures that quality is built into the product from the outset, emphasizing defect prevention, rapid detection, and efficient removal by applying the right test types at the appropriate stages and levels of the development lifecycle.

This chapter explores key Agile testing methods:

  • Test-Driven Development (TDD)
  • Acceptance Test-Driven Development (ATDD)
  • Behavior-Driven Development (BDD)

Test-Driven Development (TDD) is a software development practice where developers write automated test cases before writing the functional code. The development process follows a short, repetitive cycle: write a failing test, write the minimal code to make the test pass, and then refactor the code. This approach ensures that the code is testable by design and meets the specified requirements at a granular level.

The TDD cycle, often referred to as ‘Red-Green-Refactor’, involves these steps:

  • Step 1: Add a Test - Write a concise automated test case for a new piece of functionality or improvement. This test should initially fail because the functionality doesn’t exist yet (Red).
  • Step 2: Run All Tests - Verify that the new test fails and all existing tests still pass.
  • Step 3: Write Code - Write the simplest code possible to make the new test pass (Green).
  • Step 4: Run All Tests Again - Ensure all tests, including the new one, now pass.
  • Step 5: Refactor Code - Improve the code structure and design (e.g., remove duplication, improve clarity) without changing its external behavior. Ensure tests continue to pass after refactoring.
  • Step 6: Repeat - Continue the cycle for the next piece of functionality.

TDD is primarily applied at the unit and integration test levels. It fosters a strong safety net of tests, enabling confident refactoring and evolution of the codebase. Popular TDD frameworks include JUnit (Java), NUnit (.NET), PyTest (Python), and Jest (JavaScript). Effective TDD relies on continuous communication and collaboration, particularly between developers.

Benefits of TDD include better code design, reduced defect rates, and executable documentation in the form of tests. For further learning, explore resources on ‘xUnit’ frameworks and Martin Fowler’s articles on TDD.

Acceptance Test-Driven Development (ATDD) focuses on defining acceptance criteria from a user’s perspective before development begins. It involves collaboration between business stakeholders (like Product Owners), developers, and testers to create concrete examples of how the software should behave. These examples are then translated into automated acceptance tests.

The ATDD process typically involves:

  • Step 1: Discuss - Collaboratively define acceptance criteria for a user story, often using examples. This usually involves the ‘Three Amigos’ (Product Owner/BA, Developer, Tester).
  • Step 2: Distill - Formalize these examples into testable acceptance tests. These tests initially fail.
  • Step 3: Develop - Write the code to implement the functionality, aiming to pass the acceptance tests.
  • Step 4: Demo - Demonstrate the implemented functionality, showing that it passes the acceptance tests and meets the user’s needs. Automate these tests for continuous validation.

ATDD ensures that development is aligned with business requirements and user expectations. It helps clarify requirements early and provides a shared understanding across the team. Tools like Cucumber, SpecFlow, and FitNesse can support ATDD by allowing acceptance tests to be written in a business-readable format. Regression testing suites are often built from these automated acceptance tests.

Behavior-Driven Development (BDD) is an evolution of TDD and ATDD. It emphasizes collaboration and shared understanding by describing software behavior in a natural, domain-specific language, typically using the Gherkin syntax (Given-When-Then). This makes test scenarios accessible to non-technical team members and stakeholders.

Key aspects of BDD:

  • Shared Language: Uses structured natural language (e.g., Gherkin) to describe scenarios, fostering clear communication between business, development, and testing.
  • Outside-In Approach: Focuses on the system’s behavior from the user’s perspective, driving development from features down to unit-level implementation.
  • Living Documentation: BDD scenarios serve as executable specifications, ensuring documentation stays synchronized with the system’s actual behavior.

Example of a BDD scenario using Gherkin:

Feature: User Login
Scenario: Successful login with valid credentials
Given the user is on the login page
When the user enters valid username and password
And clicks the login button
Then the user should be redirected to the dashboard

Popular BDD frameworks include Cucumber (Ruby, Java, JS, etc.), SpecFlow (.NET), and Behave (Python). BDD helps bridge the communication gap, ensures features deliver real business value, and supports continuous testing through automated scenarios.