Home > Articles > Programming

Getting Started with ATDD: Overcoming the Biggest Mistakes Right from the Start

If you want to introduce ATDD to a project or client, common sense says to begin by choosing the tool you want to use. So why does Markus Gärtner, author of ATDD by Example: A Practical Guide to Acceptance Test-Driven Development, quash that common-sense notion? Because it doesn't work.
Like this article? We recommend

If you're like me, you become amazed when you find out that common sense doesn't work as well as most people believe. Take weight loss, for example. Until recently I believed that I could count calories, track my weight, and that's all I needed to do to lose weight—well, maybe some exercising. Unfortunately, that plan didn't work for me. Since 2009, I've occasionally exercised up to six days per week, and I tried to eat less, but none of this effort showed up on my weight measurements.

After trying hard with the common-sense approach for more than three years, the situation changed when I found out that counting calories wasn't what I needed to do. Rather, I needed to change my diet. Measuring not only my weight but also the circumferences of my waist, upper arms, and upper legs helped me to lose 20 kilograms (about 44 pounds) in four months. All that I had needed was to read about a collection of things that worked for other people, and then decide which ones I wanted to try. Timothy Ferriss recorded such a collection in The 4-Hour Body [1] that I used as a basis, and I added some curious exploration.

The same lessons can be applied to acceptance test-driven development (ATDD). Teams usually start off wrong; they don't consider the right mixture of process, people, and tools. For most teams, the common approach to ATDD starts with selecting a tool, but getting started means considering a lot more before deciding on the tool. For some teams this rule may be surprising, but they're usually better off with postponing the tool decision until after more-pressing issues have been settled. Last year, a colleague approached me with a question: "We want to introduce acceptance tests and ATDD to a client. What tool should we start with?" It took me about an hour to introduce her to a better question: "Where do we start the approach?"

ATDD isn't about a tool like FitNesse, Cucumber, or Robot Framework. ATDD is about making sure that your development team develops the right product. A particular tool might help you in doing that, but it will also expose problems in your approach if you started on the wrong foot. Therefore, before starting with acceptance tests or ATDD, I prefer to introduce a working approach and then decide on the tool. The tool question needs to be answered at some point, but first we have to ask other demanding questions on our way to success.

Where Should I Start?

Okay, where should we actually start? In my practice, I start with an example. Working together, the team identifies a case that would derive the greatest benefit from being automated.

It's challenging to come up with a first approach. At this early point, the team doesn't know what to develop. We have to establish communication between the business stakeholders and the team. If we succeed with this plan, and trust in the team, we'll find out the details later.

Next we have to tackle the question of who should be included in the discussion. Ideally, I would include all team members, but sometimes doing so isn't practical or doesn't add value. Some forces involved in this decision need a closer look.

After settling these demanding questions, we choose a format. Notice that we're not yet down to the question of the tool, but we're starting to strive toward it. The format we choose will limit the choice of the tool, but the tool itself should be our last consideration. Instead of thinking about the tool, we should work for clarity in how we write down our examples.

The right approach first, the right people second, the right format third. Let's take a look into these separate ingredients.

The Right Approach

With ATDD, recognize that there is no "right" approach in general, but rather a right approach in the context of your team and your situation. For example, if you have an onsite customer as one of the core practices in extreme programming, you can probably rely on more informal specifications, because you can have discussions with your customer more often. If your customers and users are in a different building than the one housing your development team, you'll have to come up with a different approach.

Some teams start by holding specification workshops a week before their iteration starts. Some establish informal specifications with a group of three people, one or two days before the iteration planning. Others involve the end user. If your end user can free time only every other month, you might schedule a whole day and discuss more stories for the upcoming iterations.

Whatever your approach, leave enough room to come up with answers to puzzling questions. One of my teams had no easy access to their business users; sometimes they even seemed to contradict themselves. If you discuss acceptance criteria and examples during your iteration planning, you won't have a chance to avoid such contradictions. On the other hand, if you leave one or two days between discussing upcoming stories and planning, you'll benefit from just-in-time planning, as well as anticipating changes from users.

In any case, choose just enough time before the iteration planning to allow you to derive sufficient examples from complicated upcoming stories. For some teams, this might mean getting together the day before a one-week sprint; others might set aside a half day, one week before starting the next of their three-week iterations. Leave enough time to clarify upcoming questions for your customers and product owners.

The Right People

Who needs to be involved? Generally you should include people who can raise technical questions that are difficult to answer, and who can identify shortcomings and side-effects of the decisions you make. Minimally, this means including a programmer, a tester, and a representative from the business side. (George Dinwiddie calls this constellation "the Three Amigos." [2]) Or you might choose to gather your whole team. In any case, be sure to include at least one person from the three specialties. In a future article, we'll take a closer look at why these specification workshops outperform traditional requirements documents and specifications.

The Right Format

There are a lot of different ways to write down the examples available to you. I usually start with a simplistic verbal description, making sure to reflect the user goals in these examples. At this point, I try to avoid thinking about particular user-interface implementation details, which would cause my examples to be tied to the user interface later. I don't want to end up with a test maintenance problem if I have to revisit all of my examples just because the GUI changed to include a new button.

If I start seeing a pattern in my examples, I might decide to use a tabulated format. Tables usually express one common flow through the system in a repeated way. For example, consider the following table.

Numerator

Denominator

Quotient

1

1

1

6

2

3

42

7

6

This table calculates the quotient of two given numbers for a variety of values. In any row of the table, the examples reflect the same operation: Given the numerator and denominator in the first two columns of the table, the quotient is expressed in the third column. The operation doesn't change at this point. You can express such a pattern in a less verbose way by using this sort of table structure. You can find the same concept as a parameterized test in xUnit frameworks, for example.

In most automated tests, I try to go for a structure that follows the three-phase test approach: We have some pre-conditions to settle, after which we have a single operation that triggers some behavior in the system under test, and finally we check any post-conditions that we can observe in the system. In the table above, the first two columns reflect the pre-conditions for our quotient test. The operation following the example is always the same—calculate the quotient of these two numbers. The expected results denoted in the third column will be asserted.

The BDD style Given/When/Then reflects the same approach to automation. Other names for this pattern include Arrange-Act-Assert and Setup-Execute-Verify. They all boil down to the same underlying concept.

Selecting a Tool

Sooner or later you'll face the decision of which tool to use. What's the right choice? After considering how you would like to work with ATDD, deciding who will be included in your discussions, and choosing the format that expresses your choice, find the tool that best suits those needs. At this point you've made all the difficult decisions. Maybe you even gained some experience by fostering communication first.

Your selected people might restrict the tool choice. For example, your product owner might not be comfortable with xUnit tests. On the other hand, if neither customers nor users will be looking closely at the examples once they're automated, maybe there's no need to choose a tool based on its user-friendliness for non-technical people. The long-term benefit of using the right tool definitely is based on who will actively use the tool. All the stakeholders of your decision should be able to live and work with the tool selection; that's why you need to include them right from the start in your decision-making.

If you decided in favor of a tabulated format, you may be limited to alternatives such as FitNesse, Robot Framework, or Concordion. Choosing a BDD-style format using Given/When/Then leaves your options more open. You can use one of the tools I just mentioned, or go for BDD-specific tools such as Cucumber, CucumberJVM, JBehave, or NBehave.

Some tools provide the ability to extract higher-level concepts from a set of given operations. These keywords (also known as scenario tables) come in handy if you want to provide non-technical testers with the ability to work alone on a set of predefined tests and still make progress. The development team prepares one or two examples with some variations. The keyword abilities of the tool give your testers a sort of "scripting" functionality, so that they can generate more tests based on the first prototype, without the need to develop much code in between.

One piece of advice: If you're considering an open source tool, make sure that it has an active user community. You don't want to start automating your examples and run into a problem with test number 13,372—only to find out that the product was abandoned five years ago by its users. You would have to evaluate a new tool anyway, but the transition might cost a lot of effort—despite your best intentions to keep your tests maintainable.

Getting Started with ATDD

All the successful teams I've worked with on ATDD shared one thing: They started with one approach, and they reflected on it regularly. During those retrospectives, they came up with necessary improvements if the approach stopped working for them. If you keep this practice in mind, you can essentially start with any approach. Strive for the approach that gets the least resistance from your team, and let them gather experience. As a coach, I make sure that my teams address concerns when they come up, and I enable them to make changes as needed. Only then are they free to adapt their process as indicated—even if I'm long gone.

The right approach, the inclusion of the right people, and the right format will drive your choice of a tool for ATDD, but you shouldn't avoid changing the tool if necessary. You might even start with record-and-playback tools, if you start to grow your own test library. Over time you'll build up more and more domain-specific tools for your application. These can easily be reused if you happen to change directions with your tool selection. Most teams that I've seen failing with ATDD stopped treating test automation as software development, and they gave up once the tools stopped serving them. Since they hadn't built up a reusable toolset, they couldn't easily change to a different tool. They abandoned ATDD altogether, just because they started on the wrong path.

Instead of failing like that, develop code that glues your application to the examples. By "develop," I mean "apply relentless refactoring," and I also drive the test automation code with TDD. Then I'll have a safety net that I can trust. I'll also be in an advantageous position if I have to make the difficult choice to replace my favorite tool—that change will be a lot less painful for me and my team.

References

[1] Timothy Ferriss, The 4-Hour Body: An Uncommon Guide to Rapid Fat-Loss, Incredible Sex, and Becoming Superhuman. Crown Archetype, 2010.

[2] George Dinwiddie, "The Three Amigos: All for One and One for All," StickyMinds.com, 11/29/2011.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020