{"id":120,"date":"2011-09-30T15:01:00","date_gmt":"2011-09-30T15:01:00","guid":{"rendered":"http:\/\/blog.agilityfeat.com\/?p=120"},"modified":"2011-09-30T15:01:00","modified_gmt":"2011-09-30T15:01:00","slug":"4-tips-for-automating-your-acceptance-tests","status":"publish","type":"post","link":"https:\/\/agilityfeatpanama.com\/en\/blog\/2011\/09\/4-tips-for-automating-your-acceptance-tests\/","title":{"rendered":"4 Tips For Automating Your Acceptance Tests"},"content":{"rendered":"<p><em>This article was published in Sogeti&#8217;s QANews on September 30, 2011. See their article <a href=\"http:\/\/agilityfeat.com\/files\/QANewsArticle_4TipsForAutomatingAcceptanceTests_ArinSime_Sept2011.pdf\">here<\/a><\/em><\/p>\n<p>Acceptance tests are a great way to improve collaboration between testers, developers, and customers. When all three parties agree ahead of time how to test the feature, it makes it more likely the developer will deliver working code.<\/p>\n<p>Automating those acceptance tests is even better, because now the tester can easily execute all previous acceptance tests written and ensure that new features are not breaking previously existing code.<\/p>\n<p><strong>Brief introduction to ATDD<\/strong><\/p>\n<p>Acceptance Test Driven Development (ATDD) is a powerful way to write acceptance criteria for your agile project\u2019s user stories.<\/p>\n<p>Instead of just writing a list of requirements, you write acceptance criteria in a specific format. Your acceptance tests are written in simple formats, but they can be turned into executable code.<\/p>\n<p>These acceptance tests are written before development is done, and so when the tests are executed the first time, they will all fail. This is a good thing!<\/p>\n<p>The developer now knows exactly what they need to do to write the feature. They keep developing code until the acceptance tests pass, and then they are done.<\/p>\n<p>Writing your \u201crequirements\u201d as executable code that the developer can use will improve communication between the customer, tester, and developer. Ideally all three parties will sit down together to write the acceptance tests, and then the developer can take it from there to implement the code.<\/p>\n<p><strong>Manual or Automated ATDD?<\/strong><\/p>\n<p>You could write your acceptance tests with the developer, and then have testers manually test them at the end of the project. In a loose sense this is still acceptance test driven development.<\/p>\n<p>But you will get much more value out of it if you write the tests so they can be automated. Then testers can quickly execute all the acceptance tests written for the project (even beyond the current features being developed), and they will have confidence that the new development is not breaking old features.<\/p>\n<p>Cucumber is a common framework for automating acceptance tests, and the tips in this article assume you are using it. Cucumber is implemented in Ruby, but you can use it to test virtually any system, regardless of whether your system is written in Ruby, Java, .NET, etc.<\/p>\n<p>Cucumber also has multilingual support. So you can write your tests in English, Spanish, or many other languages.<\/p>\n<p><strong>Tip #1: Adopt the Given\/When\/Then format<\/strong><\/p>\n<p>The Cucumber testing framework uses a language called Gherkin for writing the acceptance tests. These tests follow this basic pattern:<\/p>\n<blockquote><p><em>Given [some precondition or starting state]<\/em><\/p>\n<p><em>When [the user does something]<\/em><\/p>\n<p><em>Then [something happens]<\/em><\/p><\/blockquote>\n<p>Using this format helps to make the test clear, and encourages you to properly describe the preconditions for the test, what initiates the test, and what the expected outcome is. This simple pattern makes it easy to visually scan a test and see what it does.<br \/>\n<strong> Tip #2: Group scenarios based on common backgrounds<\/strong><\/p>\n<p>In many of your tests, the \u201cGiven\u201d clauses will be very similar. Gherkin allows you to save time by putting these common pre conditions in a \u201cBackground\u201d section of the test file so that you are not writing duplicate code.<\/p>\n<p>This also helps you determine when you can group scenarios together in the feature test. If a scenario does not fit the background pre conditions, then it should go somewhere else.<\/p>\n<p>As an example, you might initially consider grouping together tests that deal with adding an item to a shopping cart. But on further consideration, you notice there are really two different set of features to consider: adding items to the cart when you are a logged in shopper, and when a new customer adds items to their cart. These could be considered two distinct sets of features since they have different pre-conditions.<\/p>\n<p><strong>Tip #3: Mock external dependencies<\/strong><\/p>\n<p>Automated tests need to be fast, otherwise you will not run them often enough. Teams may delay starting the automated tests if they take hours to run. The tester says \u201cWe\u2019ll start it just as soon as a couple more developers check in their code\u2026\u201d<\/p>\n<p>But this means you are delaying the rework of any bugs found, and that can slow down the whole project.<\/p>\n<p>If your automated tests take too long, it\u2019s may be due to an external dependency. Is the test making a call to another system? Can you \u201cmock\u201d that other system and replace it with fake code so that the test runs faster?<\/p>\n<p>Frameworks like JMock and nMock make this possible, so that you can focus on testing your code instead of worrying about the external systems it depends on.<\/p>\n<p><strong>Tip #4: Example scenarios to build common terminology<\/strong><\/p>\n<p>The Cucumber framework is great, but it relies on \u201cubiquitous terminology.\u201d You don\u2019t want to write different pieces of test code for all of these statements:<\/p>\n<blockquote><p><em>Given that a user has logged in<\/em><br \/>\n<em> Given that the user logs in<\/em><br \/>\n<em> Given that the user is logged in<\/em><\/p><\/blockquote>\n<p>When you read these sentences as a human, it\u2019s obvious they all mean the same thing. But the automated testing framework doesn\u2019t understand that, and it expects you to implement three different pieces of test code for them.<\/p>\n<p>Using common terminology across your team is important, so consider posting examples of common test steps on the team room wall or on a wiki. Then you can re-use other test code more easily.<\/p>\n<p><strong>Automating ATDD improves communication<\/strong><\/p>\n<p>Many teams want to speed up testing, increase automation, and improve communication between developers, testers, and customers. Automating your acceptance tests with Cucumber can definitely achieve all of these goals, and is worth the investment.<\/p>\n<p>Following these tips will help you make the most of your automated ATDD adoption.<\/p>\n<p><strong>About the author<\/strong><\/p>\n<p><em>Arin Sime is owner of AgilityFeat, where he provides agile coaching and development services. Arin is a regular speaker at agile conferences and user groups, including the recent XP2011 conference in Madrid. Arin holds a Masters degree in Management of I.T. from the University of Virginia. You can reach him at Arin@AgilityFeat.com or on twitter <a title=\"Follow Arin on Twitter\" href=\"http:\/\/twitter.com\/#!\/ArinSime\">@ArinSime<\/a>.<\/em><\/p>","protected":false},"excerpt":{"rendered":"<p>This article was published in Sogeti&#8217;s QANews on September 30, 2011. See their article here Acceptance tests are a great way to improve collaboration between testers, developers, and customers. When all three parties agree ahead of time how to test the feature, it makes it more likely the developer will deliver working code. Automating those [&hellip;]<\/p>","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":""},"categories":[4],"tags":[5,37,25,26,27],"jetpack_featured_media_url":"","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>4 Tips For Automating Your Acceptance Tests - AgilityFeat Panama Software Test Center<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/agilityfeatpanama.com\/en\/blog\/2011\/09\/4-tips-for-automating-your-acceptance-tests\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"4 Tips For Automating Your Acceptance Tests - AgilityFeat Panama Software Test Center\" \/>\n<meta property=\"og:description\" content=\"This article was published in Sogeti&#8217;s QANews on September 30, 2011. See their article here Acceptance tests are a great way to improve collaboration between testers, developers, and customers. When all three parties agree ahead of time how to test the feature, it makes it more likely the developer will deliver working code. Automating those [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/agilityfeatpanama.com\/en\/blog\/2011\/09\/4-tips-for-automating-your-acceptance-tests\/\" \/>\n<meta property=\"og:site_name\" content=\"AgilityFeat Panama Software Test Center\" \/>\n<meta property=\"article:published_time\" content=\"2011-09-30T15:01:00+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"5 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/34.200.113.64\/#website\",\"url\":\"https:\/\/34.200.113.64\/\",\"name\":\"AgilityFeat Panama Software Test Center\",\"description\":\"AgilityFeat Panama offers customized, multilevel web and mobile software testing for a variety of industries.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/34.200.113.64\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/agilityfeatpanama.com\/en\/blog\/2011\/09\/4-tips-for-automating-your-acceptance-tests\/#webpage\",\"url\":\"https:\/\/agilityfeatpanama.com\/en\/blog\/2011\/09\/4-tips-for-automating-your-acceptance-tests\/\",\"name\":\"4 Tips For Automating Your Acceptance Tests - AgilityFeat Panama Software Test Center\",\"isPartOf\":{\"@id\":\"https:\/\/34.200.113.64\/#website\"},\"datePublished\":\"2011-09-30T15:01:00+00:00\",\"dateModified\":\"2011-09-30T15:01:00+00:00\",\"author\":{\"@id\":\"https:\/\/34.200.113.64\/#\/schema\/person\/c8d60d597071526db386b2b8a4afac64\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/agilityfeatpanama.com\/en\/blog\/2011\/09\/4-tips-for-automating-your-acceptance-tests\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/34.200.113.64\/#\/schema\/person\/c8d60d597071526db386b2b8a4afac64\",\"name\":\"arin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/34.200.113.64\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cc498e210512c707ed769986dd745896?s=96&d=mm&r=g\",\"caption\":\"arin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/posts\/120"}],"collection":[{"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":0,"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"wp:attachment":[{"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agilityfeatpanama.com\/en\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}