Cucumber features and steps for a mature app should evolve towards a mini

Cucumber features and steps for a mature app should

This preview shows page 292 - 294 out of 517 pages.

Cucumber features and steps for a mature app should evolve towards a “mini-language” appropriate for that app. For example, an app for scheduling vacations for hospital nurses would have scenarios that make heavy use of domain-specific terms such as shift, seniority, holiday, overtime, and so on, rather than focusing on the low-level interactions between the user and each view. Pitfall: Trying to predict what you need before you need it. Part of the magic of Behavior-Driven Design (and Test-Driven Development in the next chapter) is that you write the tests before you write the code you need, and then you write code needed to pass the tests. This top-down approach again makes it more likely for your efforts to be useful, which is harder to do when you’re predicting what you think you’ll need. This observation has also been called the YAGNI principle—You Ain’t Gonna Need It. Pitfall: Careless use of negative expectations. Beware of overusing Then I should not see... . Because it tests a negative condition, you might not be able to tell if the output is what you intended—you can only tell what the output isn’t . Many, many outputs don’t match, so that is not likely to be a good test. For example, if you were testing for the absence of “Welcome, Dave!” but you accidentally wrote Then I should not see “Greetings, Dave!” , the scenario will pass even if the app incorrectly emits “Welcome, Dave!”. Always include positive expectations such as Then I should see... to check results. Pitfall: Careless use of positive expectations. Even if you use positive expectations such as Then I should see... , what if the string you’re looking for occurs multiple times on the page? For example, if the logged-in user’s name is Emma and your scenario is checking whether Jane Austen’s book Emma was correctly added to the shopping cart, a scenario step Then I should see “Emma” might pass even if the cart isn’t working. To avoid this pitfall, use Capybara’s within helper, which constrains the scope of matchers such as I should see to the element(s) matching a given CSS selector, as in Then I should see ”Emma” within ”div#shopping_cart” , and use unambiguous HTML id or class attributes for page elements you want to name in your scenarios. The Capybara documentation lists all the matchers and helpers. Pitfall: Delivering a story as “done” when only the happy path is tested. As should be clear by now, a story is only a candidate for delivery when both the happy path and the most important sad paths have been tested. Of course, as Chapter 8 describes, there are many more ways for something to work incorrectly than to work correctly, and sad-path tests are not intended to be
Image of page 292
a substitute for finer-grained test coverage. But from the user’s point of view, correct app behavior when the user accidentally does the wrong thing is just as important as correct behavior when she does the right thing.
Image of page 293
Image of page 294

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors