This repository was archived by the owner on Dec 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 522
Update better-gherkin.md #873
Open
atdd-bdd
wants to merge
6
commits into
cucumber:main
Choose a base branch
from
atdd-bdd:patch-4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a8d0012
Update better-gherkin.md
atdd-bdd 3d7e980
Update better-gherkin.md
atdd-bdd a2c8828
Update better-gherkin.md
atdd-bdd bfde4cf
Update better-gherkin.md
atdd-bdd ff133e7
Update better-gherkin.md
atdd-bdd a98a379
Merge branch 'cucumber:main' into patch-4
atdd-bdd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,8 @@ As a side benefit, in consequence your scenarios will be a lot shorter and much | |
|
|
||
| One way to make scenarios easier to maintain and less brittle is to use a declarative style. Declarative style describes the behaviour of the application, rather than the implementation details. Declarative scenarios read better as "living documentation". A declarative style helps you focus on the value that the customer is getting, rather than the keystrokes they will use. | ||
|
|
||
| ## Imperative style | ||
|
|
||
| Imperative tests communicate details, and in some contexts this style of test is appropriate. On the other hand, because they are so closely tied to the mechanics of the current UI, they often require more work to maintain. Any time the implementation changes, the tests need to be updated too. | ||
|
|
||
| Here's an example of a feature in an imperative style: | ||
|
|
@@ -64,6 +66,8 @@ Scenario: Subscriber with a paid subscription can access "FreeArticle1" and "Pai | |
|
|
||
| Each step is a precise instruction. The inputs and expected results are specified exactly. But it's easy to imagine changes to the application which would require changing these tests. The available options for free versus paid subscriptions can change. Even the means of logging in could change. What if, in the future, users log in with a voice interface or a thumbprint? | ||
|
|
||
| ## Declarative style | ||
|
|
||
| A more declarative style hides the details of how the application's capabilities are implemented. | ||
|
|
||
| ``` | ||
|
|
@@ -80,3 +84,39 @@ Scenario: Subscriber with a paid subscription can access both free and paid arti | |
| Then she sees a Free article and a Paid article | ||
| ``` | ||
| With a declarative style, each step communicates an idea, but the exact values aren't specified. The details of *how* the user interacts with the system, such as which specific articles are free or paid, and the subscription level of different test users, are specified in the step definitions (the automation code that interacts with the system). The subscription packages could change in the future. The business could change what content is available to subscribers on free and paid plans, without having to change this scenario and other scenarios that use the same step definitions. If another subscription level is added later, it's easy to add a scenario for that. By avoiding terms like “click a button” that suggest implementation, the scenario is more resilient to implementation details of the UI. The intent of the scenario remains the same, even if the implementation changes later. In addition, having too many implementation details in a scenario, makes it harder to understand the intended behaviour it illustrates. | ||
|
|
||
| ## A third style | ||
|
|
||
| There is a style that is intermediate between these two. The exact values are specified in the scenario, but the way the user interacts with the system is not. This style uses data tables with domain terms as the column headers. The step definitions can be reused for multiple scenarios with different data in the table. In this example, the scenarios for free and paid subscribers use the same step definitions. | ||
|
|
||
| ```Gherkin | ||
| Scenario: Free subscribers see only the free articles | ||
| Given articles are: | ||
| | Title | For Subscription | | ||
| | Free Article 1 | Free | | ||
| | Paid Article 1 | Paid | | ||
| And user is logged in as: | ||
| | User Name | Password | Subscription | | ||
| | [email protected] | validPassword123 | Free | | ||
| When articles are displayed | ||
| Then articles displayed are: | ||
| | Title | | ||
| | Free Article 1 | | ||
|
|
||
| Scenario: Subscriber with a paid subscription can access both free and paid articles | ||
| Given articles are: | ||
| | Title | For Subscription | | ||
| | Free Article 1 | Free | | ||
| | Paid Article 1 | Paid | | ||
| And user is logged in as: | ||
| | User Name | Password | Subscription | | ||
| | [email protected] | validPassword123 | Paid | | ||
| When articles are displayed | ||
| Then articles displayed are: | ||
| | Title | | ||
| | Free Article 1 | | ||
| | Paid Article 1 | | ||
| ``` | ||
|
|
||
| These scenarios could be executed in three ways - automated using the core components, automated using a UI automation framework, or manually executed. The logic is checked with the first, the plumbing between the UI and the core is checked with the second, and the ease of use is checked with the third. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This step would then become redundant in both scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was split on whether the login should become a separate scenario or not. I was matching the data in the imperative style
There would at least need to be a step that said the logged user had a paid.free subscription. Keeping that as a data table emphasizes that Subscription is a domain term.
I could write a section on splitting scenarios, which might come after this one.