Value in stories
Generally, the features on a project should be those that will provide a value to the customer, for some definition of ‘value’. We can use the template
As a <role>
I want <something>
So that <I get some value or benefit>
to help us describe the stories which we use to prompt conversation about what that value is. The value doesn’t have to be monetary; it could mean a reduction in risk, an ease of maintenance, the ability to use a technology that will still be supported in five years’ time.
Value in code
A piece of code should provide value to the class, module, application, system etc. in which it resides. If a piece of value can be encapsulated into one block of code, chances are that it’ll be easier to read, maintain, find and delete, should that value ever become obsolete.
Here’s an example of something that I didn’t find any value in. I was coding John Conway’s Game of Life as a kata.
public void testShouldReturnTrueIfTheCellHasLife() {
Grid grid = new Grid();
grid.causeBirth(4, 8);
assertTrue(grid.hasLife(4, 8));
}
This isn’t valuable, because I can easily make this pass with
public class Grid {
....
public boolean hasLife() {
return true;
}
}
One way to get around this is to add another test:
public void testShouldReturnFalseIfTheCellHasNoLife() {
Grid grid = new Grid();
grid.causeBirth(4, 8);
assertFalse(grid.hasLife(4, 2));
}
So now we have two tests, describing one benefit. I prefer this:
public void testShouldDetermineIfACellHasLife() {
Grid grid = new Grid();
grid.causeBirth(4, 8);
assertTrue(grid.hasLife(4, 8));
assertFalse(grid.hasLife(4, 2));
}
One block of code, one value which it provides. Using two tests for this would mean that the value was split; neither test has is truly valuable without the other.
Value in tests
The test describes the behaviour of the code; that is, the features that the code provides, and the value that you can expect from those features.
The test doesn’t fully define the behaviour. There’s no definition for what happens if the parameters are negative numbers, for instance, or any indication as to whether the grid can cope with non-integers. There’s no indication of what might cause the behaviour of the grid to change.
Normally, when we have a story, we have some scenarios which are associated with that story. The scenarios form acceptance tests for that story, but they may not completely define the system behaviour. After all, if all the scenarios defined for a story play out, then any bug is just a scenario we didn’t think of – and we still find bugs.
In a story, the story card is just a placeholder for a conversation about that story; the scenarios are there to help you work out if the story has been developed properly.
In a test, the name of the test method forms the ‘story card’ for that piece of code, and the implementation of the test forms the ‘scenarios’. But it’s still just a placeholder for conversation.