Consistency in Features

November 18, 2011

Writing good features is difficult. One way to write better features is to read them critically. Two criteria useful for this are consistency and exclusivity. So a feature should be consistent and exclusive, what does this mean.

Consistency

For a feature to be consistent the following needs to apply

  1. The filename (including path) of the feature should be consistent with the title of the feature
    • inconsistent: features/purchasing.feature and Feature: Writing a blog
    • consistent: features/blog/new_article/ and Feature: New article
  2. The narrative should be consistent with the title

  3. A scenario title should be consistent with the narrative

  4. A scenarios steps should be consistent with the scenario title

n.b. In addition each thing lower down the list should be consistent with all the things above it.

Typical Inconsistencies

  1. Change of vocabulary: e.g. changing from talking about articles to talking about posts
  2. Introducing concepts outside the context. A classic in web applications is introducing different behaviour for different user types.
  3. Scenarios about separate content that appears on the same web page but has nothing to do with the feature.

Exclusivity

This is partially covered by being consistent. What it is saying is that a feature should only contain scenarios that are part of its narrative. It might also be saying that these scenarios belong here and nowhere else. In practice having no overlap between features is probably impossible. However lots of overlap is probably a good indicator that things could be better

Summary

Reading your features critically and applying rules of consistency and exclusivity is useful in creating simpler features that have greater focus. This should be done before, during and after implementation. In the long run its far more important that your features make sense than go green. If they make sense but are red you will have lots of context to help create your fix. If they make no sense then when they go red (and they will some day) then finding a fix will be much harder.