<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ivan Poiraudeau</title>
    <description>The latest articles on Forem by Ivan Poiraudeau (@ivan_poiraudeau).</description>
    <link>https://forem.com/ivan_poiraudeau</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F456362%2F0d8395a7-1a21-4579-8939-278ad70b9b00.png</url>
      <title>Forem: Ivan Poiraudeau</title>
      <link>https://forem.com/ivan_poiraudeau</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ivan_poiraudeau"/>
    <language>en</language>
    <item>
      <title>Concise Gherkin - How brevity improves BDD scenarios</title>
      <dc:creator>Ivan Poiraudeau</dc:creator>
      <pubDate>Tue, 27 Feb 2024 09:42:34 +0000</pubDate>
      <link>https://forem.com/upslide/concise-gherkin-how-brevity-improves-bdd-scenarios-3d86</link>
      <guid>https://forem.com/upslide/concise-gherkin-how-brevity-improves-bdd-scenarios-3d86</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;💡 New to behavior-driven development? It’s a fantastic way to collaborate and produce better documentation.&lt;br&gt;
Here’s an &lt;a href="https://cucumber.io/docs/bdd/" rel="noopener noreferrer"&gt;introduction&lt;/a&gt;, with details about its dedicated language, &lt;a href="https://cucumber.io/docs/gherkin/reference/" rel="noopener noreferrer"&gt;Gherkin&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In behavior-driven development (BDD), it’s best practice to &lt;a href="https://cucumber.io/blog/bdd/keep-your-scenarios-brief/" rel="noopener noreferrer"&gt;keep your scenarios BRIEF&lt;/a&gt;, an acronym for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Business language&lt;/strong&gt;: The words used in a scenario should be drawn from the business domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real data&lt;/strong&gt;: Examples should use concrete, real data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Intention revealing&lt;/strong&gt;: Scenarios should reveal the &lt;em&gt;intent&lt;/em&gt; of what the actors in the scenario are trying to achieve, rather than describing the &lt;em&gt;mechanics&lt;/em&gt; of how they will achieve it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Essential&lt;/strong&gt;: The purpose of a scenario is to illustrate how a rule should behave. Any part of a scenario that does not directly contribute to this purpose are incidental and should be removed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Focused&lt;/strong&gt;: Most scenarios should be focused on illustrating a single rule.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Last year, &lt;a href="https://upslide.net/" rel="noopener noreferrer"&gt;my team at UpSlide&lt;/a&gt; overhauled our user management system through BDD. We noticed that focusing on &lt;strong&gt;brevity&lt;/strong&gt; let us validate several principles at once: our scenarios were becoming more intention revealing, essential and focused.&lt;/p&gt;

&lt;h3&gt;
  
  
  Brevity reveals scenarios intention
&lt;/h3&gt;

&lt;p&gt;Consider this login step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="nf"&gt;Given &lt;/span&gt;I visit &lt;span class="s"&gt;"/login"&lt;/span&gt;
&lt;span class="nf"&gt;When &lt;/span&gt;I enter &lt;span class="s"&gt;"Bob"&lt;/span&gt; in the &lt;span class="s"&gt;"user name"&lt;/span&gt; field
  &lt;span class="nf"&gt;And &lt;/span&gt;I enter &lt;span class="s"&gt;"tester"&lt;/span&gt; in the &lt;span class="s"&gt;"password"&lt;/span&gt; field
  &lt;span class="nf"&gt;And &lt;/span&gt;I press the &lt;span class="s"&gt;"login"&lt;/span&gt; button
&lt;span class="nf"&gt;Then &lt;/span&gt;I should be greeted with a welcome message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This scenario is filled with unimportant and brittle implementation details. By prioritizing brevity, we can simplify it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="nf"&gt;When &lt;/span&gt;Bob logs in
&lt;span class="nf"&gt;Then &lt;/span&gt;Bob should be greeted with a welcome message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scenario intention becomes clearer: it emphasizes the need for a welcome message upon login, without getting bogged down in implementation specifics.&lt;/p&gt;

&lt;h3&gt;
  
  
  Brevity keeps scenarios essential
&lt;/h3&gt;

&lt;p&gt;Here is a scenario about email notifications:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="nf"&gt;Given &lt;/span&gt;Alice's email storage is not full
&lt;span class="nf"&gt;And &lt;/span&gt;Alice is not offline
&lt;span class="nf"&gt;When &lt;/span&gt;Alice sends an email
&lt;span class="nf"&gt;Then &lt;/span&gt;Alice should get notified that the email was sent.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Alice’s storage is full or if she’s offline, the email indeed cannot be sent so she shouldn’t get notified that it was.&lt;/p&gt;

&lt;p&gt;In most email happy paths however, these conditions won’t apply and the reader doesn’t need to know about them.&lt;br&gt;
In the test implementation, we should instead ensure the &lt;a href="https://en.wikipedia.org/wiki/System_under_test" rel="noopener noreferrer"&gt;system under test&lt;/a&gt; has enough message storage for Alice and operates as if it’s online. We can then streamline the scenario:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="nf"&gt;When &lt;/span&gt;Alice sends an email
&lt;span class="nf"&gt;Then &lt;/span&gt;Alice should get notified that the email was sent.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Considering storage space and internet connection separately lets us explore other behaviors, each with their own scenarios:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="nf"&gt;Given &lt;/span&gt;Alice's email storage is full
&lt;span class="nf"&gt;When &lt;/span&gt;Alice sends an email
&lt;span class="nf"&gt;Then &lt;/span&gt;Alice should be notified that the email couldn't be sent
&lt;span class="nf"&gt;And &lt;/span&gt;that she needs to free up storage

&lt;span class="nf"&gt;Given &lt;/span&gt;Alice is offline
&lt;span class="nf"&gt;When &lt;/span&gt;Alice sends an email
&lt;span class="nf"&gt;Then &lt;/span&gt;Alice should be notified that the email couldn't be sent
&lt;span class="nf"&gt;And &lt;/span&gt;that she needs to connect to the Internet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Brevity focuses scenarios
&lt;/h3&gt;

&lt;p&gt;Follow this example from Monopoly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="nf"&gt;Given &lt;/span&gt;the player went over the GO square [A]
&lt;span class="nf"&gt;When &lt;/span&gt;the player falls on a CHANCE square [B]
&lt;span class="nf"&gt;Then &lt;/span&gt;the player should earn 200₩
&lt;span class="nf"&gt;And &lt;/span&gt;the player should take the top CHANCE card
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can see that mixing [A] and [B] in other ways (&lt;em&gt;not&lt;/em&gt; going over the GO square, &lt;em&gt;not&lt;/em&gt; falling on the CHANCE square) could lead to a combinatorial explosion of scenarios.&lt;/p&gt;

&lt;p&gt;Again, noting this scenario lacks brevity leads us to more independent scenarios:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gherkin"&gt;&lt;code&gt;&lt;span class="nf"&gt;When &lt;/span&gt;the player goes over the GO square
&lt;span class="nf"&gt;Then &lt;/span&gt;the player should earn 200₩

&lt;span class="nf"&gt;When &lt;/span&gt;the player falls on a CHANCE square
&lt;span class="nf"&gt;Then &lt;/span&gt;the player should take the top CHANCE card
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  More on BDD principles
&lt;/h3&gt;

&lt;p&gt;In a process akin to other forms of writings, brevity helps me uncover the core ideas behind the system I’m specifying.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 If you’re keen on crafting &lt;strong&gt;concise scenarios,&lt;/strong&gt; I’ve put together a &lt;strong&gt;step-by-step&lt;/strong&gt; kata to assist you:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://trello.com/b/qO5804nS/kata-behavior-driven-developmentlink" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Check it here!&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I didn’t talk much about the two other key principles, Business Language and Real Data. This video by Gáspár Nagy (creator of SpecFlow, a .NET BDD framework) delves deeper into them:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/awwFfCYoGFQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>bdd</category>
      <category>gherkin</category>
      <category>documentation</category>
      <category>codequality</category>
    </item>
  </channel>
</rss>
