From a8d0012eccf308d90f3452873bf3d0649dad9be7 Mon Sep 17 00:00:00 2001 From: atdd-bdd <37565969+atdd-bdd@users.noreply.github.com> Date: Fri, 31 Mar 2023 14:24:38 -0400 Subject: [PATCH 1/5] Update better-gherkin.md Added an intermediate style between imperative and declarative --- content/docs/bdd/better-gherkin.md | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/content/docs/bdd/better-gherkin.md b/content/docs/bdd/better-gherkin.md index 7370ffd6..3ce7a7e3 100644 --- a/content/docs/bdd/better-gherkin.md +++ b/content/docs/bdd/better-gherkin.md @@ -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 stepdef tables with domain terms as the column headers. The step definitions can be reused for mulitple scenarios with different data in the table. In this example, the scenarios for free and paid subscribers use the same step defs. + +```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 +| User Name | Password | Subscription | +| freeFrieda@example.com | 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 +| User Name | Password | Subscription | +| paidPattya@example.com | 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. + From 3d7e98002f26757d3eeabf9babfa0e2c29683121 Mon Sep 17 00:00:00 2001 From: atdd-bdd <37565969+atdd-bdd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:50:21 -0400 Subject: [PATCH 2/5] Update better-gherkin.md --- content/docs/bdd/better-gherkin.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/content/docs/bdd/better-gherkin.md b/content/docs/bdd/better-gherkin.md index 3ce7a7e3..e38fec5a 100644 --- a/content/docs/bdd/better-gherkin.md +++ b/content/docs/bdd/better-gherkin.md @@ -87,21 +87,21 @@ With a declarative style, each step communicates an idea, but the exact values a ## 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 stepdef tables with domain terms as the column headers. The step definitions can be reused for mulitple scenarios with different data in the table. In this example, the scenarios for free and paid subscribers use the same step defs. +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 | + Given articles are: + | Title | For Subscription | + | Free Article 1 | Free | + | Paid Article 1 | Paid | And user is logged in -| User Name | Password | Subscription | -| freeFrieda@example.com | validPassword123 | Free | + | User Name | Password | Subscription | + | freeFrieda@example.com | validPassword123 | Free | When articles are displayed Then articles displayed are -| Title | -| Free Article 1 | + | Title | + | Free Article 1 | Scenario: Subscriber with a paid subscription can access both free and paid articles Given articles are: @@ -118,5 +118,5 @@ Then articles displayed are | 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. +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. From a2c8828237278cede137e62a14079ce495b883d3 Mon Sep 17 00:00:00 2001 From: atdd-bdd <37565969+atdd-bdd@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:52:15 -0400 Subject: [PATCH 3/5] Update better-gherkin.md --- content/docs/bdd/better-gherkin.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/docs/bdd/better-gherkin.md b/content/docs/bdd/better-gherkin.md index e38fec5a..cdc8d427 100644 --- a/content/docs/bdd/better-gherkin.md +++ b/content/docs/bdd/better-gherkin.md @@ -95,11 +95,11 @@ Scenario: Free subscribers see only the free articles | Title | For Subscription | | Free Article 1 | Free | | Paid Article 1 | Paid | -And user is logged in +And user is logged in as: | User Name | Password | Subscription | | freeFrieda@example.com | validPassword123 | Free | When articles are displayed -Then articles displayed are +Then articles displayed are: | Title | | Free Article 1 | @@ -108,11 +108,11 @@ Given articles are: | Title | For Subscription | | Free Article 1 | Free | | Paid Article 1 | Paid | -And user is logged in +And user is logged in as: | User Name | Password | Subscription | | paidPattya@example.com | validPassword123 | Paid | When articles are displayed -Then articles displayed are +Then articles displayed are: | Title | | Free Article 1 | | Paid Article 1 | From bfde4cf388a61ae25bdbe6674aafd1f9af362113 Mon Sep 17 00:00:00 2001 From: atdd-bdd <37565969+atdd-bdd@users.noreply.github.com> Date: Wed, 24 May 2023 16:59:18 -0400 Subject: [PATCH 4/5] Update better-gherkin.md Split off the login scenario from the display scenarios. The logon follows along with the first scenario on this page. --- content/docs/bdd/better-gherkin.md | 37 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/content/docs/bdd/better-gherkin.md b/content/docs/bdd/better-gherkin.md index cdc8d427..0aa999e1 100644 --- a/content/docs/bdd/better-gherkin.md +++ b/content/docs/bdd/better-gherkin.md @@ -87,17 +87,30 @@ With a declarative style, each step communicates an idea, but the exact values a ## 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. +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. The following example separates the login scenario from the display scenarios. ```Gherkin + +Scenario: Logon +Given users are + | User Name | Password | Subscription | + | freeFrieda@example.com | validPassword123 | Free | + | paidPattya@example.com | validPassword123 | Free | +When user logs in + | User Name | freeFrieda@example.com | + | Password | validPassword123 | +Then user is logged in with + | Subscription | + | Free | + 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 | - | freeFrieda@example.com | validPassword123 | Free | + | Subscription | + | Free | When articles are displayed Then articles displayed are: | Title | @@ -105,18 +118,18 @@ Then articles displayed are: 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 | + | Title | For Subscription | + | Free Article 1 | Free | + | Paid Article 1 | Paid | And user is logged in as: -| User Name | Password | Subscription | -| paidPattya@example.com | validPassword123 | Paid | + | Subscription | + | Paid | When articles are displayed Then articles displayed are: -| Title | -| Free Article 1 | -| Paid Article 1 | + | 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. +The Given of the last two scenarios could be put into a Background scenario, if desired. 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 way, the plumbing between the UI and the core is checked with the second way, and the ease of use is checked with the third way. From ff133e7e1082b285e9126bd372492ade42f76eb5 Mon Sep 17 00:00:00 2001 From: atdd-bdd <37565969+atdd-bdd@users.noreply.github.com> Date: Wed, 24 May 2023 17:10:54 -0400 Subject: [PATCH 5/5] Update better-gherkin.md Add conjunctions to the scenarios. --- content/docs/bdd/better-gherkin.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/content/docs/bdd/better-gherkin.md b/content/docs/bdd/better-gherkin.md index 0aa999e1..1e60da5f 100644 --- a/content/docs/bdd/better-gherkin.md +++ b/content/docs/bdd/better-gherkin.md @@ -92,40 +92,40 @@ There is a style that is intermediate between these two. The exact values are sp ```Gherkin Scenario: Logon -Given users are +Given the users are | User Name | Password | Subscription | | freeFrieda@example.com | validPassword123 | Free | - | paidPattya@example.com | validPassword123 | Free | -When user logs in + | paidPattya@example.com | validPassword456 | Free | +When a user logs in | User Name | freeFrieda@example.com | | Password | validPassword123 | -Then user is logged in with +Then the user is logged in with | Subscription | | Free | Scenario: Free subscribers see only the free articles - Given articles are: +Given the articles are: | Title | For Subscription | | Free Article 1 | Free | | Paid Article 1 | Paid | -And user is logged in as: +And the user is logged in as: | Subscription | | Free | -When articles are displayed -Then articles displayed are: +When the articles are displayed +Then the displayed articles are: | Title | | Free Article 1 | Scenario: Subscriber with a paid subscription can access both free and paid articles -Given articles are: +Given the articles are: | Title | For Subscription | | Free Article 1 | Free | | Paid Article 1 | Paid | -And user is logged in as: +And the user is logged in as: | Subscription | | Paid | -When articles are displayed -Then articles displayed are: +When the articles are displayed +Then the displayed articles are: | Title | | Free Article 1 | | Paid Article 1 |