- •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
152 Speciication by Example
Although I’ve mostly presented web applications as examples when talking about user interfaces, the same advice is applicable to other types of user interfaces. Automating just below the skin of the application allows us to validate worklow and session constraints but still shorten the feedback time compared to running tests through the user interface. After looking into managing automation in general, it’s time to cover two speciic areas that caused automation problems for many teams: user interfaces and data management.
Automating user interfaces
When it comes to automation, dealing with user interfaces was the most challenging aspect of Speciication by Example for the teams covered by my research. Almost all the teams I interviewed made the same mistake early on. They speciied tests intended to be automated through user interfaces as series of technical steps, often directly writing user interface automation commands in their speciications.
User interface automation libraries work in the language of screen objects, essentially software design. Describing speciications in that language directly contradicts the key ideas of reining the speciication (see the “Scripts are not speciications” and “Speciications should be about business functionality, not software design” sections in chapter 8). In addition to making speciications hard to understand, this makes automated tests incredibly hard to maintain long term. Pierre Veragen worked on a team that had to throw away all the tests after a small change to the user interface:
User interface tests were task oriented (click, point) and therefore tightly coupled to the implementation of the GUI, rather than activity oriented. There was a lot of duplication in tests. FitNesse tests were organized according to the way UI was set up. When the UI was updated, all these tests had to be updated. The translation from conceptual to technical changed. A small change to the GUI, adding a ribbon control, broke everything. There was no way we could update the tests.
The investment they put into tests up to that point was wasted, because it was easier for them to throw away all those tests than to update them. The team decided to invest in restructuring the architecture of the application to enable easier testing.
If you decide to automate validation for some of your speciications through a user interface, managing that automation layer eficiently is probably going to be one of the key activities for your team. Here are some good ideas on how to automate tests through a user interface and still keep them easy to maintain.
Chapter 9 Automating validation without changing speciications 153
Specify user interface functionality at a higher level of abstraction
Pushing the translation from the business language to the language of user interface objects into the automation layer helps to avoid long-term maintenance problems. This essentially means specifying user interface tests at a higher level of abstraction. Aslak Hellesøy says that this was one of the key lessons he learned early on:
We realized that if we could write tests on a higher level, we could achieve a lot of beneits. This allowed us to change the implementation without having to change a lot of feature scripts. The tests were a lot easier to read, because they were shorter. We had hundreds of these tests, and just by glancing over them it was much easier to see where the things were. They were much more resilient to change.
Lance Walton had a similar experience, which resulted in creating classes in the integration layer that represented operations of user interface screens and then raising the level of abstraction to worklows and inally to higher-level activities. He explains:
We went through the predictable path of writing tests in “type this, click this button” style with lots of repetition between tests. We had a natural instinct to refactor and realized we needed a representation of the screens. I very much go with the early XP rules: If you have a small expression that has a meaning, refactor it to a method and give it a name. It was predictable that we’ll have to log in for every single test, and that should be reusable. I didn’t quite know how to do it, but I knew that was going to happen. So we came up with screen classes.
The next thing to realize was that we kept going through the same sequence of pages—it was a worklow. The next stage was to understand that the worklow still had to do with the solution we designed, so actually let’s forget about worklow and focus on what the user is trying to achieve.
So we had pages that contained the details, then we had the task level above that, then we had the whole worklow on top of that, and then we inally had the goal that the user is trying to achieve. When we got to that level, the tests could be composed very quickly, and they were robust against the changes.
Reorganizing the automation layer to handle activities—and focusing tests on speciications, not scripts—helped reduce the maintenance costs of automated tests signiicantly, Walton said:
154 Speciication by Example
Early on you had to log in to see anything. At one point there was a notion that you could see a whole bunch of stuff before logging in, and you would only be asked to log in when you followed a link. If you have a whole lot of tests that log in at the start, the irst problem you have is that, until you remove the login step, all your tests break. But you have to log in after you follow a link, so a whole bunch of tests would break because of that. If you have abstracted that away, the fact that your test is logging in as a particular person doesn’t mean that it’s doing that immediately—you just store that information and use it when asked to log in.
The tests move smoothly through. Of course, you need additional tests to check when you are required to log in, but this is a different concern. All the tests that are about testing whether the users can achieve their goal are robust even with that fairly signiicant change. It was surprising and impressive to me that we could make this change so easily. I truly began to see the power we have to control this stuff.
The fact that a user had to be logged in for a particular action was separated from the actual activity of illing in the login form, submitting it, and logging in. The automation layer decided when to perform that action in the worklow (and if it needed to be performed at all). This made the tests based on the speciications much more resilient to change. It also raised the level of abstraction for user interface actions, allowing the readers to understand the entire speciication easier.
Specifying |
user |
interface functionality from |
a |
higher level of |
abstraction allows |
|||
teams |
to |
avoid |
the |
translation |
between |
business and user |
interface concepts. |
|
It also |
makes |
the |
acceptance |
tests easier to understand and more resilient to |
||||
change, |
reducing |
the |
long-term |
maintenance |
costs. |
|
See the sidebar “Three levels of user interface automation” later in this chapter for an idea how to organize UI test automation to keep all the beneits of reining the speciication and reduce long-term maintenance costs.
Check only UI functionality with UI speciications
When: User interface contains complex logic
If your executable speciications |
are described as interactions with- |
user inter |
face elements, specify only user |
interface functionality. |
|