- •Contents
- •Preface
- •Acknowledgments
- •About the author
- •About the cover illustration
- •Higher product quality
- •Less rework
- •Better work alignment
- •Remember
- •Deriving scope from goals
- •Specifying collaboratively
- •Illustrating using examples
- •Validating frequently
- •Evolving a documentation system
- •A practical example
- •Business goal
- •An example of a good business goal
- •Scope
- •User stories for a basic loyalty system
- •Key Examples
- •Key examples: Free delivery
- •Free delivery
- •Examples
- •Living documentation
- •Remember
- •Tests can be good documentation
- •Remember
- •How to begin changing the process
- •Focus on improving quality
- •Start with functional test automation
- •When: Testers own test automation
- •Use test-driven development as a stepping stone
- •When: Developers have a good understanding of TDD
- •How to begin changing the team culture
- •Avoid “agile” terminology
- •When: Working in an environment that’s resistant to change
- •Ensure you have management support
- •Don’t make test automation the end goal
- •Don’t focus on a tool
- •Keep one person on legacy scripts during migration
- •When: Introducing functional automation to legacy systems
- •Track who is running—and not running—automated checks
- •When: Developers are reluctant to participate
- •Global talent management team at ultimate software
- •Sky Network services
- •Dealing with sign-off and traceability
- •Get sign-off on exported living documentation
- •When: Signing off iteration by iteration
- •When: Signing off longer milestones
- •Get sign-off on “slimmed down use cases”
- •When: Regulatory sign-off requires details
- •Introduce use case realizations
- •When: All details are required for sign-off
- •Warning signs
- •Watch out for tests that change frequently
- •Watch out for boomerangs
- •Watch out for organizational misalignment
- •Watch out for just-in-case code
- •Watch out for shotgun surgery
- •Remember
- •Building the right scope
- •Understand the “why” and “who”
- •Understand where the value is coming from
- •Understand what outputs the business users expect
- •Have developers provide the “I want” part of user stories
- •When: Business users trust the development team
- •Collaborating on scope without high-level control
- •Ask how something would be useful
- •Ask for an alternative solution
- •Make sure teams deliver complete features
- •When: Large multisite projects
- •Further information
- •Remember
- •Why do we need to collaborate on specifications?
- •The most popular collaborative models
- •Try big, all-team workshops
- •Try smaller workshops (“Three Amigos”)
- •Pair-writing
- •When: Mature products
- •Have developers frequently review tests before an iteration
- •When: Analysts writing tests
- •Try informal conversations
- •When: Business stakeholders are readily available
- •Preparing for collaboration
- •Hold introductory meetings
- •When: Project has many stakeholders
- •Involve stakeholders
- •Undertake detailed preparation and review up front
- •When: Remote Stakeholders
- •Prepare only initial examples
- •Don’t hinder discussion by overpreparing
- •Choosing a collaboration model
- •Remember
- •Illustrating using examples: an example
- •Examples should be precise
- •Don’t have yes/no answers in your examples
- •Avoid using abstract classes of equivalence
- •Ask for an alternative way to check the functionality
- •When: Complex/legacy infrastructures
- •Examples should be realistic
- •Avoid making up your own data
- •When: Data-driven projects
- •Get basic examples directly from customers
- •When: Working with enterprise customers
- •Examples should be easy to understand
- •Avoid the temptation to explore every combinatorial possibility
- •Look for implied concepts
- •Illustrating nonfunctional requirements
- •Get precise performance requirements
- •When: Performance is a key feature
- •Try the QUPER model
- •When: Sliding scale requirements
- •Use a checklist for discussions
- •When: Cross-cutting concerns
- •Build a reference example
- •When: Requirements are impossible to quantify
- •Remember
- •Free delivery
- •Examples should be precise and testable
- •When: Working on a legacy system
- •Don’t get trapped in user interface details
- •When: Web projects
- •Use a descriptive title and explain the goal using a short paragraph
- •Show and keep quiet
- •Don’t overspecify examples
- •Start with basic examples; then expand through exploring
- •When: Describing rules with many parameter combinations
- •In order to: Make the test easier to understand
- •When: Dealing with complex dependencies/referential integrity
- •Apply defaults in the automation layer
- •Don’t always rely on defaults
- •When: Working with objects with many attributes
- •Remember
- •Is automation required at all?
- •Starting with automation
- •When: Working on a legacy system
- •Plan for automation upfront
- •Don’t postpone or delegate automation
- •Avoid automating existing manual test scripts
- •Gain trust with user interface tests
- •Don’t treat automation code as second-grade code
- •Describe validation processes in the automation layer
- •Don’t replicate business logic in the test automation layer
- •Automate along system boundaries
- •When: Complex integrations
- •Don’t check business logic through the user interface
- •Automate below the skin of the application
- •Automating user interfaces
- •Specify user interface functionality at a higher level of abstraction
- •When: User interface contains complex logic
- •Avoid recorded UI tests
- •Set up context in a database
- •Test data management
- •Avoid using prepopulated data
- •When: Specifying logic that’s not data driven
- •Try using prepopulated reference data
- •When: Data-driven systems
- •Pull prototypes from the database
- •When: Legacy data-driven systems
- •Remember
- •Reducing unreliability
- •When: Working on a system with bad automated test support
- •Identify unstable tests using CI test history
- •Set up a dedicated continuous validation environment
- •Employ fully automated deployment
- •Create simpler test doubles for external systems
- •When: Working with external reference data sources
- •Selectively isolate external systems
- •When: External systems participate in work
- •Try multistage validation
- •When: Large/multisite groups
- •Execute tests in transactions
- •Run quick checks for reference data
- •When: Data-driven systems
- •Wait for events, not for elapsed time
- •Make asynchronous processing optional
- •Getting feedback faster
- •Introduce business time
- •When: Working with temporal constraints
- •Break long test packs into smaller modules
- •Avoid using in-memory databases for testing
- •When: Data-driven systems
- •Separate quick and slow tests
- •When: A small number of tests take most of the time to execute
- •Keep overnight packs stable
- •When: Slow tests run only overnight
- •Create a current iteration pack
- •Parallelize test runs
- •When: You can get more than one test Environment
- •Try disabling less risky tests
- •When: Test feedback is very slow
- •Managing failing tests
- •Create a known regression failures pack
- •Automatically check which tests are turned off
- •When: Failing tests are disabled, not moved to a separate pack
- •Remember
- •Living documentation should be easy to understand
- •Look for higher-level concepts
- •Avoid using technical automation concepts in tests
- •When: Stakeholders aren’t technical
- •Living documentation should be consistent
- •When: Web projects
- •Document your building blocks
- •Living documentation should be organized for easy access
- •Organize current work by stories
- •Reorganize stories by functional areas
- •Organize along UI navigation routes
- •When: Documenting user interfaces
- •Organize along business processes
- •When: End-to-end use case traceability required
- •Listen to your living documentation
- •Remember
- •Starting to change the process
- •Optimizing the process
- •The current process
- •The result
- •Key lessons
- •Changing the process
- •The current process
- •Key lessons
- •Changing the process
- •Optimizing the process
- •Living documentation as competitive advantage
- •Key lessons
- •Changing the process
- •Improving collaboration
- •The result
- •Key lessons
- •Changing the process
- •Living documentation
- •Current process
- •Key lessons
- •Changing the process
- •Current process
- •Key lessons
- •Collaboration requires preparation
- •There are many different ways to collaborate
- •Looking at the end goal as business process documentation is a useful model
- •Long-term value comes from living documentation
- •Index
128 Speciication by Example
Start with basic examples; then expand through exploring
When: Describing rules with many parameter combinations
To solve the problem described in the previous section, Crispin’s team decided to write only high-level speciications before starting to work on a story, leaving detailed tests for later.
A tester and a developer speciied a happy path together when they started to work on a story. A developer then automated the speciication and wrote the code, allowing testers to reuse the automation framework and add test cases. Testers then explored the system and experimented with different examples. If they found a failing test case, they went back to the programmers to extend the speciication and get the problem ixed.
Instead of overcomplicating the speciication, |
basic examples help drive the |
happy path and put the automation structure |
in place. |
Additional examples can then be tried based on risk, and speciication can be extended gradually. This is an interesting solution to handle cases where classes of equivalence aren’t easy to determine at irst and where the implementation drives edge cases.
Speciications should be focused
A speciication should describe a single thing—a business rule, a function, or a step of a process. Such focused speciications are easier to understand than the ones that specify several related rules. A speciication should also be focused on only the key attributes of examples that are important for the item it’s trying to demonstrate.
Focus brings two important beneits to speciications: Focused speciications are short, so they’re easier to understand than longer, less-focused ones. They’re also easier to maintain. A speciication that covers several rules will be inluenced by changes in all of the involved areas of the system. This will cause the automated tests based on the speciication to break more often. Even worse, when such a test breaks, it will be hard to pinpoint problems.
Use “Given-When-Then” language in speciications
In order to: Make the test easier to understand
As a |
rule |
of thumb, a |
speciication |
should declare the context, specify a single |
action, |
and |
then deine |
the expected |
post-conditions. |
Chapter 8 Reining the speciication |
129 |
A good way to remember this is Given-When-Then or Arrange-Act-Assert. Given-When- Then is a common format for specifying system behaviors, popularized by the early behavior-driven-development articles. It requires us to write scenarios of system behaviors in three parts:
•Given a precondition
•When an action happens
•Then the following post-conditions should be satisied
Some automation tools, such as Cucumber4 and SpecFlow,5 use exactly that language for executable speciications. See igure 8.1 for an example. Even with different tools that might use a tabular, keyword-based or free-form text system, structuring speciications to follow a Given-When-Then low is an excellent idea.
Triggering a single action is crucial. This ensures that a speciication is focused on only that action. If a speciication lists several actions, a reader will have to analyze and understand how these actions collaborate to produce the inal effect in order to understand the results.
If a set of actions is important from a business low perspective, it’s probably important enough to be given a name and used as a higher-level concept, so it should be captured in a higher-level method in the domain code. This higher-level method can then be listed in the speciication.
A speciication can still deine several preconditions and postconditions (multiple items in the Given and Then sections) as long as they’re all directly related to the function speciied by the test. The following example of a Cucumber test has two preconditions and two postconditions:
Scenario: New user, suspicious transaction
Given a user with no previous transaction history,
And the user’s account registration country is the UK,
When the user places an order with delivery country U.S.,
Then the transaction is marked as suspicious,
But the user sees order status as “Pending.”
A potential pitfall with Given-When-Then language is that it’s like prose, which often encourages people to think about lows of interactions rather than expressing business functionality directly. Use the advice from section “Scripts are not speciications” earlier in this chapter to avoid such problems.
4http://www.cukes.info
5http://speclow.org
130 Speciication by Example
Don’t explicitly set up all the dependencies in the speciication
When: Dealing with complex dependencies/referential integrity
In data-driven projects that require complex coniguration, objects can rarely be created in isolation. For example, the domain validation rules for a payment method might require that it belongs to a customer, that a customer must have a valid account, and so on.
Many teams |
made the mistake of putting all |
the |
coniguration |
and |
setup for |
||
all prerequisites into the speciication. Although |
this |
makes |
the |
speciication |
|||
explicit |
and |
complete from a conceptual perspective, |
it can |
also |
make |
it diicult |
|
to read |
and |
understand. |
|
|
|
|
|
In addition, any change to any of the objects or attributes in the coniguration will break the test based on this speciication, even if it isn’t directly related to the speciied rule.
Describing all dependencies explicitly can also hide data-related issues, so this is especially dangerous on data-driven projects.
Jonas Bandi worked on a project to rewrite a legacy data management system for schools, where one of the biggest problems was understanding the existing data. The team wrote speciications that were setting up the entire context dynamically. The context in the speciications was based on the understanding of the team, not on realistic data variations. The team detected many gaps and inconsistencies in requirements only when they connected the code to the data coming from the legacy system, in the middle of the iterations (see the “Examples should be realistic” section in chapter 7).
The Bekk Consulting team working on the Norwegian Dairy Herd Recording System had a similar issue but from a different perspective. Their project is also data driven, with many objects requiring complex setup. At irst, they were deining the entire context in each executable speciication. This required people to perfectly guess all the dependencies. If some data was missing, the tests based on the speciications would fail because of data integrity constraints, even though the code was implemented properly.
These issues can be solved better in the automation layer, not in the speciication. Move all the dependencies that aren’t related to the goal of the speciication to the automation layer, and keep the speciication focused on only the important attributes and objects. Also see the “Test data management” section in chapter 9 for some good solutions to technical data management problems.