    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Executable Documentation Doesnâ€™t Have To Slow You Down [Test-XML-1]</title>
        <link>https://members.accu.org/index.php/articles/1806</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Overload test issue</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c327/">00</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Executable Documentation Doesnâ€™t Have To Slow You Down [Test-XML-1]</h1>
<p><strong>Author:</strong>&nbsp;Martin Moene</p>
<p>
<strong>Date:</strong> 07 July 2013 21:42:36 +01:00 or Sun, 07 July 2013 21:42:36 +01:00</p>
<p><strong>Summary:</strong>&nbsp;Comprehensibility of end-to-end scenarios and quick feedback of unit tests are competing goals. Seb Rose introduces Cucumber with tags to meet both needs.

[Generated from XML by Martin Moene; old XSL, apparently not matching current XML.]</p>
<p><strong>Body:</strong>&nbsp;<h2 >
   
   Business engagement
</h2>
<p >
   
   First, we need to address the lack of engagement of the business. The regular complaint
   is that the business people are too busy to spend time working on the examples with
   the development team, and the only way round this is to point out that unless someone
   who understands the businessÃ¢â‚¬â„¢s needs is involved in the product evolution, then itÃ¢â‚¬â„¢s
   unlikely that the end result is going to be satisfactory. There are lots of ways to
   arrange business involvement, from having a fully empowered Product Owner co-located
   with the development team, through to scheduling regular times that a business person
   will be available to work with the team. The key point is that whoever works with
   the team needs to be authorised to make decisions regarding the development of the
   product Ã¢â‚¬â€œ if all questions lead to an Ã¢â‚¬Å“IÃ¢â‚¬â„¢ll get back to you on thatÃ¢â‚¬Â then there will
   be problems.
</p>
<p >
   
   A less satisfactory solution is for the development team to produce all the examples
   and then have them reviewed and signed-off. Many of the benefits of deriving the examples
   collaboratively are lost if you work this way:
</p>
<p >
   
   Notice that IÃ¢â‚¬â„¢m not talking about automation at all. No tools have been mentioned.
   Nor have I introduced any of the techy acronyms (BDD [<a href="#
   North">
   North</a>
   ], ATDD [<a href="#
   Hendrickson">
   Hendrickson</a>
   ], SbE [<a href="#
   Adzic11">
   Adzic11</a>
   ],  EDD, TDD). IÃ¢â‚¬â„¢m talking about collaboration pure and simple. This style of collaboration
   has been popularised by the Agile Manifesto [<a href="#
   Agile">
   Agile</a>
   ], one of whose principles states:
</p>
<p >
      
      The most efficient and effective method of conveying information to and within a development
      team is face-to-face conversation.</span></p>
<p >
   
   You donÃ¢â‚¬â„¢t have to be agile to work like this (most organisations that think they are
   Ã¢â‚¬ËœagileÃ¢â‚¬â„¢ donÃ¢â‚¬â„¢t work like this), but working like this will improve communication in
   any organisation and remove many of the hurdles from the real job of delivering something
   that the customer wants.
</p>
<h2 >
   
   Automated examples
</h2>
<p >
   
   At this point you can decide to go no further, but there is great value to be had
   by considering automating some (or all) of the examples that were collaboratively
   authored:
</p>
<p >
   
   Once you have decided to automate, youÃ¢â‚¬â„¢ll need to choose your approach. For the purposes
   of this article I will use examples written in Gherkin [<a href="#
   Cucumber">
   Cucumber</a>
   ] (which interprets examples for Cucumber [<a href="#
   Cucumber">
   Cucumber</a>
   ]). I am a fan of Cucumber/Gherkin, but there are many other tools available, most
   of which will automate the execution of examples.
</p>
<p >
   
   LetÃ¢â‚¬â„¢s assume we have the example below, that deals with registering at some website:
</p>
<p >
      
      Feature: Sign Up	Scenario: New user redirected to their own page		When I sign up for
      a new account		Then I should be taken to my feeds page		And I should see a greeting
      message</span></p>
<p >
   
   When Cucumber runs this scenario (example) it tries to match each step (introduced
   by the keywords Given, When, Then, And, But) with some glue code that exercises the
   system under test. The glue code can be written in various languages, depending on
   which port of Cucumber you are using, but for the purposes of this article I will
   limit myself to Java and so will be using Cucumber-JVM [<a href="#
   HellesÃƒÂ¸y12">
   HellesÃƒÂ¸y12</a>
   ]. Each method in the glue code is annotated with a regular expression, against which
   Cucumber tries to match the text of each step:
</p>
<li >
   
   if the method returns without raising an exception the step passes
</li>
<li >
   
   if an exception propagates out of the method the step fails
</li>
<p >
   
   How you implement the step definitions is up to you, and depends on the nature of
   your system. The example above might:
</p>
<p >
   
   The point is that the text in the example describes the behaviour, while the step
   definitions (the glue code) specify how to exercise the system. An example glue method
   would be:
</p>
<h2 >
   
   Examples everywhere
</h2>
<p >
   
   Newcomers to this style of working often adopt a style in which every example is executed
   as an end-to-end test. End-to-end tests mimic the behaviour of the entire system and
   create an exampleÃ¢â‚¬â„¢s context by interacting directly with the UI, and the full application
   stack is involved throughout (databases, app servers etc.). This sort of test is very
   useful for verifying that an application has deployed correctly, but can become quite
   a bottleneck if you use it for validating every behaviour of the system. The Testing
   Pyramid (see Figure 1) [<a href="#
   Fowler12">
   Fowler12</a>
   ] was created to give a visual hint about the relative number of Ã¢â‚¬ËœthickÃ¢â‚¬â„¢ end-to-end
   tests and Ã¢â‚¬ËœthinÃ¢â‚¬â„¢ unit tests. In the middle are the component/integration tests that
   verify interactions within a subset of the entire system. (The Ã¢â‚¬ËœExploratory and ManualÃ¢â‚¬â„¢
   cloud at the top is a reminder that not all tests can be automated, and that the amount
   of effort needed here is very system dependent.)
</p>
<p >
   
   It may be reasonable to use the example scenario above as a Ã¢â‚¬ËœHappy PathÃ¢â‚¬â„¢ end-to-end
   test, demonstrating that the whole application is hanging together. However, there
   are some other situations that emerged when this feature was discussed, some of which
   were:
</p>
<p >
   
   These questions are still independent of how the system is actually going to be implemented,
   but we can start fleshing out some examples:
</p>
<p >
      
      Scenario: Duplicate user registration	Given I already have an account	When I sign
      up for a new account	Then I should see the Ã¢â‚¬Å“User already existsÃ¢â‚¬Â error message</span></p>
<p >
      
      Scenario: Unacceptable credentials at signup	Given my credentials are unacceptable	When
      I sign up for a new account	Then I should see the Ã¢â‚¬Å“Unacceptable credentialsÃ¢â‚¬Â error
      message</span></p>
<p >
   
   These extra examples could be implemented using the whole application stack, but then
   the runtime of the example suite begins to rise as we execute more end-to-end tests.
   Instead, we could decompose these examples into:
</p>
<p >
      
      Scenario Outline: Display correct error message	When the registration component returns
      an &lt;error&gt;	Then the correct &lt;message&gt; should be returned</span></p>
<p >
      
      Examples:| error					| message	|| error-code-user-already-exists					| &quot;User already
      exists&quot;	|| error-code-unacceptable-credentials					| &quot;Unacceptable credentials&quot;	|</span></p>
<p >
      
      Scenario: Detect duplicate user	Given user already exists	When the registration component
      tries to create the user	Then it will return error-code-user-already-exists</span></p>
<p >
      
      Scenario: Unacceptable credentials at signup	Given the credentials are unacceptable	When
      the registration component tries to create the user	Then it will return error-code-unacceptable-credentials</span></p>
<h2 >
   
   Speed, completeness and comprehensibility
</h2>
<p >
   
   These examples should run a lot faster, but are no longer written in business language
   (if you want an explanation of Scenario Outline look at the Cucumber documentation).
   They have lost some of their benefit and have become technical tests, mainly of interest
   to the development team. If we choose to Ã¢â‚¬Ëœpush them downÃ¢â‚¬â„¢ into the unit test suite,
   where they seem to belong, then we will have lost some important documentation that
   is important to the business stakeholders.
</p>
<p >
   
   This demonstrates the conflict between keeping the examples in a form that is consumable
   by non-technical team members and managing the runtime of the executable examples.
   Teams that have ignored this issue and allowed their example suite to grow have seen
   runtimes that are counted in hours rather than minutes. Clearly this limits how quickly
   feedback can be obtained, and has led teams to try different solution approaches,
   none of which are ideal:
</p>
<p >
   
   In a recent blog post I introduced the Testing Iceberg (see Figure 2) [<a href="#
   Rose">
   Rose</a>
   ], which takes the traditional Testing Pyramid and introduces a readability waterline.
   This graphically shows that some technical tests can be made visible to the business,
   while there are some end-to-end tests that the business are not interested in. We
   want to implement our business examples in such a way that they:
</p>
<h2 >
   
   Using Cucumber
</h2>
<p >
   
   There are a few features of Cucumber that I need to introduce before describing the
   technique I use to keep my examples consumable by the business without sacrificing
   performance of the suite.
</p>
<h3 >
   
   Tags
</h3>
<p >
   
   Any Cucumber scenario can have one or more free text tags applied to it:
</p>
<p >
      
      @this_is_a_tag@a_different_tag@regressionScenario: What just happened?	When I do something	Then
      something should happen</span></p>
<p >
   
   When invoking Cucumber you can pass in tags as arguments to identify which scenarios
   should be executed. This is useful when trying to partition the example suite, to
   build a regression suite or a smoke test suite, for example.
</p>
<h3 >
   
   Hooks
</h3>
<p >
   
   Cucumber also allows you to provide setup/teardown hooks in your glue code that are
   run before and after each example. 
</p>
<h3 >
   
   Tagged hooks
</h3>
<p >
   
   And finally, Cucumber allows you to write tagged hooks, which are only run before
   scenarios that have matching tags (matching can use complex logic Ã¢â‚¬â€œ see the documentation).
</p>
<h2 >
   
   Putting it all together
</h2>
<p >
      
      Scenario: Duplicate user registration	Given I already have an account	When I sign
      up for a new account	Then I should see the &quot;User already exists&quot; error message</span></p>
<p >
   
   The benefits of working like this are:
</p>
<p >
   
   It is the business who should prioritise how to evolve a product, based on their understanding
   of the customers needs. Face to face communication between the business and the development
   team can help develop a ubiquitous language that can be used to document the behaviour
   of the system in a manner that is clear and unambiguous to all concerned. The examples
   that are produced during these conversations can then be automated, but there is an
   ongoing tension between the comprehensibility of end-to-end scenarios and the quick
   feedback of unit tests. Using Cucumber and tags it is possible to write the examples
   in an end-to-end style, but modify how they are executed (and hence their runtime
   costs) by applying or removing tags, without adversely affecting the comprehensibility
   of the example itself. 
   Ã¯ÂÂª
   
</p>
<h2 >
   
   References
</h2>
<p >
   
   
   [Adzic11]  
   http://specificationbyexample.com/key_ideas.html
   
</p>
<p >
   
   
   [Agile]  
   http://agilemanifesto.org
   
</p>
<p >
   
   
   [Cucumber]  
   http://cukes.info
   
</p>
<p >
   
   
   [Fowler]  
   http://martinfowler.com/bliki/UbiquitousLanguage.html
   
</p>
<p >
   
   
   [Fowler12]  
   http://martinfowler.com/bliki/TestPyramid.html
   
</p>
<p >
   
   
   [HellesÃƒÂ¸y12]  
   http://aslakhellesoy.com/post/20006051268/cucumber-jvm-1-0-0
   
</p>
<p >
   
   
   [Hendrickson]  
   http://testobsessed.com/2008/12/acceptance-test-driven-development-atdd-an-overview/
   
</p>
<p >
   
   
   [Keogh12]  
   http://lizkeogh.com/2012/06/01/bdd-in-the-large/
   
</p>
<p >
   
   
   [North]  
   http://dannorth.net/introducing-bdd/
   
</p>
<p >
   
   
   [Rose]  
   http://claysnow.co.uk/?p=175315341
   
</p>
<p >
   
   
   [Selenium]  
   http://docs.seleniumhq.org
   
</p></p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
