Given-When-Then is a format used in software testing
to describe the steps of a test case in a structured and clear manner. It helps to ensure that the test case is well-defined and covers all relevant scenarios. The format consists of three parts:
- Given: This is the initial setup or precondition for the test case. It describes the state or conditions that must be present before the test case can be executed.
- When: This is the action or event that triggers the test case. It describes the specific step or input that will be provided to the system under test.
- Then: This is the expected outcome or result of the test case. It describes what the system should do or display after the action or event in the When step has been completed.
Here's an example of a test case written in Given-When-Then format:
Given: The user is logged into the website. When: The user clicks the "Add to Cart" button for a product. Then: The product should be added to the user's shopping cart.
By using this format, testers can ensure that all relevant scenarios are covered and that the test case is easy to understand and reproduce.