tags:

views:

55

answers:

1

When writing a BDD scenario that is validating information on an input form, how would you list rules.

Options are:

1) A single scenario each rule 2) Scenario outline with examples for each field and rule

How do we say something is invalid that is not in a certain character set, e.g:

Given I enter a value that breaks the rule.. When I do something Then I should see an error .....

Would you generate random values that break the rule?

Thanks, James

A: 

Hi James,

With validation, I've done one of these:

  • validated each kind of thing that might go wrong, or
  • captured the validation behaviour with unit tests, then just described how I, the user, will see the validation message
  • captured the common things that users do wrong and described how the system will help me to get it right.

I find the second and third ones easier to maintain, especially using a BDD tool, given that English is hard to refactor and validation rules often change. If there's no higher-level business capability which is provided, as in the third situation, then I'd just do the second one.

BDD isn't really about testing. It's about coming to a shared understanding and capturing that in a way which helps that understanding play into the code. You get tests as a wonderful by-product.

Hope that helps.

Lunivore