To use Acceptance Test-Driven Development (ATDD) to derive test cases, follow these steps:
-
Understand the Requirements: Begin by thoroughly understanding the business requirements and acceptance criteria. These are typically defined by business stakeholders and describe the expected behavior of the system from the user's perspective.
-
Collaborative Discussion: Engage in collaborative discussions involving developers, testers, and business stakeholders. This ensures that everyone has a shared understanding of what needs to be built and helps identify any ambiguities or gaps in the requirements.
-
Write Acceptance Tests: Based on the acceptance criteria, write acceptance tests. These tests should describe the behavior of the system from the user's perspective. A common format for these tests is the Given-When-Then structure, which is easy to understand for all stakeholders.
- Given: The initial context or state of the system.
- When: The action or event that triggers the behavior.
- Then: The expected outcome or result.
-
Automate the Tests: Convert the acceptance tests into automated tests. This involves writing code that can execute these tests and verify that the system behaves as expected. Automation ensures that these tests can be run repeatedly and consistently.
-
Develop the Feature: The development team then writes the code to implement the feature. The goal is to make the acceptance tests pass, which ensures that the feature meets the business requirements.
-
Run the Tests: Execute the automated acceptance tests to verify that the feature works as expected. If the tests pass, the feature is considered done.
To derive test cases from ATDD:
-
From Acceptance Criteria: Each acceptance criterion can be translated into one or more test cases. These criteria are essentially the test cases that need to be verified.
-
Given-When-Then Format: If the acceptance tests are written in a Given-When-Then format, each scenario can be directly converted into a test case. For example:
- Given a user with a valid username and password
- When the user attempts to log in
- Then the system should grant access to the user's account
-
Collaboration: The collaborative nature of ATDD ensures that the test cases cover all aspects of the requirements, including edge cases and business rules.
-
Automation: The automated tests can be directly translated into test cases. Each automated test is a test case that verifies a specific behavior of the system.
Example:
Suppose we have a requirement for a login feature:
Requirement: As a user, I want to log in to the system so that I can access my account.
Acceptance Criteria:
- The system should allow a user to log in with a valid username and password.
- The system should not allow a user to log in with an invalid username or password.
- The system should display an error message if the login attempt fails.
From these acceptance criteria, we can derive the following test cases:
-
Valid Login:
- Given a user with a valid username and password
- When the user attempts to log in
- Then the system should grant access to the user's account
-
Invalid Username:
- Given a user with an invalid username and a valid password
- When the user attempts to log in
- Then the system should display an error message and not grant access
-
Invalid Password:
- Given a user with a valid username and an invalid password
- When the user attempts to log in
- Then the system should display an error message and not grant access
These test cases are derived directly from the acceptance criteria and cover the main scenarios and edge cases for the login feature.
By following these steps, you can effectively use ATDD to derive comprehensive test cases that ensure the software meets the business requirements and acceptance criteria.