Agile Insider reality bytes…

20Apr/10Off

Top Tips – User Centred Automated Acceptance Tests

Following on from my previous article, I thought I would share some top tips for creating automated acceptance tests for projects using user centred design.  There is nothing inherent in user centred design which prevents an agile approach being adopted and indeed agile adds huge value to user centred design by reducing the feedback loops during the "design".

The outputs from the "design" part of user centred design is usually a set of wireframes, sometimes highly graphical to be used for marketing and soliciting customer feedback.  Low fidelity wireframes, as produced by balsamiq are fantastic for exploring the solution space with minimal commitment and retain that back of a napkin look and feel which prevents misinterpretation by customers and business about how much work remains to be done making them real.  At some point, developers will get their hands on these wireframes and be tasked with "making them real".  Of course, if the developers can help create the wireframes, then so much better and what a great way to reduce that feedback loop 😉

An example wireframe...

So, we're a delivery team and we have the wireframes available which we want to use to start carving this up into stories (with a customer ideally), executable tests and working code.  Where to start...

First we want to express what we're seeing as stories so we can assign value to the stories and prioritise based on ROI.  Depending on the technology choices, these wireframes also help to perform an initial design of the application in terms of data, services, components, etc.

The stories we write can be high level stories capturing the user experience as they navigate through the site, or they can be as low level as which fields are visible within a given area of the site.

My preferred approach is to write stories and tests at the high level and as we uncover the detail capture these as smaller stories and more detailed tests.  This seems to fit naturally with user centred design and allows planning and release activities to focus on the high level stories around the user experience (which is probably why they chose to do user centred design in the first place) and allow the development and build activities to focus on delivering the smaller stories.

My top tips would be...

  • Write your stories and tests based on what you see in the wireframes
    • e.g. When a user (who is not logged in) visits the homepage they can see the "News" in the main area.  Notice that the wireframe has a single article, but this could be many articles in the future.  There is also no reason to assume this is the "Latest News", "Featured News", "Breaking News" or anything else.
  • Be constantly aware of the context (explicit or not) within the wireframe when writing your test
    • e.g. In the latest news section, we may see a "Read More" link and assume that we can simply fnid this "Read More" link on the page.  Of course, in the future, there may be more than one news article (so we want to find the "Read More" link related to a particular article) and indeed there be more sections that contain "Read More" links such as user comments (so when we implement a test around the news, we want to ensure that we are finding the correct "Read More", which means we look for it in the news section and in relation to the article(s) of interest).
  • Don't assume the wireframe is what the final implementation will be so think in abstract terms
    • e.g. if there is a button in the wireframe, this may be a clickable image later, or a tab panel.  So word your tests not on the button, but on the capability the button provides, so instead of "...and the user can click <Help>" we might have "..and the user is able to obtain <Help>".
  • Envisage alternative implementations while writing the tests and validate your test would still be valid
    • e.g. If I change this from being a form to being editable inline, does the test still work?
  • Try to be discrete in your tests, it is better to have lots of small, simple tests than a small number of tests that test too many things.
    • e.g.
      • when... can they see today's weather
      • when... can they see today's temperature
      • when... can they see tomorrow's weather
  • Use "Given, When, Then... and" to think about the scenarios you need, but try expressing them in natural english.
    • e.g.  When someone is viewing the school holidays calendar (Given) and they enter their postcode (When), the calendar should only display holidays for schools within the catchment radius (Then) and the user should be able to remove the filter (And).
    • I like to think of "Thens" as being the assertions, and with UCD this is the stuff I want to see on the screen as a result of me doing something.
    • The "Ands", which are an extension to Dan North's, I like to think of as the stuff I can now do in addition and in UCD this usually relates to new functionality which has been exposed or links that have appeared.
  • Refer to the Concordion Techniques page for some great examples of how to write robust tests in natural language.
  • Separate site aspects (navigation, login) from functional or contextual tests
  • Refactor your tests as you go to evolve a testing DSL to simplify writing future tests
  • Use personas (or metaphors) to encapsulate data
    • Bring your personas to life
      • Write them a CV, or post their key characteristics on the team wall.
    • You can validate key aspects of your persona within your test (in the "Given" section) to provide better tests by clarifying what aspects of the persona you are actually testing
      • e.g. "When Joe (who is on legal aid) views the list of local lawyers, the lawyers who provide legal aid are highlighted".  Notice that highlighted could mean anything, from promoting them to the top, changing colour, or adding a nice icon...
  • Don't create too many personas
    • Personas are very powerful, but when abused become difficult to manage.  To test functional aspects related to simple data variations use dynamic personas (e.g. when someone, who has not yet entered their postcode, accesses their profile...)
  • Think like a customer
    • Ask yourself how much money you would pay for a given feature or piece of functionality

I'm sure that I'll refine this example in the future and therefore watch this space...

4Jun/09Off

The Real Value of Test First is the Thought Process

TDD found the simple solution ;)

TDD found the simple solution 😉

Test Driven is a loaded term and means different things to different people.  I much prefer the term Test First which clearly states that the test comes before the implementation.  However, for me, the value is not necessarily in creating an executable test, but in the thought processes that Test First brings out.

One of my colleagues at emergn is constantly reminding me that when presented with a solution you need to ask yourself what is the problem. This is what lead me to question TDD and it's variants.  If you search the web for Test Driven Development, you'll uncover a wealth of information from many of the authors in my BlogRoll, as well as many variants on a theme. I think the wikipedia entry is a particularly good summary of Test Driven as it is currently understood by the community but for the real meat and bones you need to look at the articles from the thought leaders behind the practises.

However, when I look at this wealth of information, I'm now faced with the question...  OK, these are all solutions, but what is the fundamental problem they are solving?  Is it

  • Code quality/design is poor
  • Code is overly complex/difficult to test
  • Unused functionality within the code
  • Too many bugs

It is only when we understand the underlying problem fully that we can then evaluate the applicability/suitability of a particular approach.  Indeed, it is this lack of a clearly defined problem which makes it impossible to determine which approach is best, since we can't define any tests up front...  This is actually a little bit of a paradox, but highlights for me one of the most important points about TDD.  TDD is a solution to too many problems and in certain cases is not a very good solution.

Testing should be about proving functionality, but unfortunately we too often see TDD trying to address non testing issues like design and code quality.  Of course, code needs to be testable, but it is not the responsibility of the Testing to enforce this, it is the responsibility of the design, but this is (unfortunately IMHO) the missing piece in most methodologies...  Indeed, the approach of writing the "Simplest Possible Thing" to pass a test is possibly my biggest bug-bear with TDD.  This approach often means you can pass tests with no functionality other than hard coded return values, now that has to be the biggest process smell ever.

I'm going to stop using TDD, or Test Driven now and use instead the term I prefer which is Test First.  For me, this means that before I do anything, I will determine ahead of time how I would test it.  The immediate benefit (a.k.a value) I get from determining how to test something is I'm also starting to think about (dare I suggest design) things like apis/design/interaction/responsibilities.  This is not the same as BDUF (big design up front), instead it is just enough thought at just the right moment to (hopefully)  prevent a disaster.  I can then apply some cost/benefit analysis with a pinch of risk analysis to assign a value to actually writing all the tests that TDD would have forced you to write, or just a small percentage to cover the important or more complex functionality.

Of course, in many cases I will actually create executable tests for many of those uncovered during this thought exercise, but will I go through the whole Red/Green/Refactor cycle, possibly not.  For me the Red/Green/Refactor is like micro context switching.  I prefer a slightly longer period of focus and therefore I may write quite a few tests at the same time before applying that context switch to go into coding mode.  This of course is my personal preference and undoubtedly would be scorned upon by the dogmatic TDD zealots, but if this is what makes me more productive, and without a baseline problem statement I challenge them to prove that this is not the best way to do your testing.

Test First allows me to

  • Understand the problem I'm trying to solve
  • Think about how I will solve it (just enough design)
  • Uncover any unknowns or risks hidden in the initial problem statement
  • Produce high quality code which has just enough tests

Many of the Test Driven approaches do indeed address many of the initial problems stated earlier, but are they the only solution to these problems?  Indeed, are these problems actually just symptoms of even deeper problems?  If the problem is simply that your code is very tightly coupled and difficult to test then the best ROI will probably come not from TDD but from up-skilling your development team on fundamental design principles (unskilled developers was the real problem in the first place and TDD can't solve that).

Resources: