We are just getting started with BDD in our company, and we are currently trying to write our first features. We have created something like the following:
Feature: There can only be one
It is important that there is only one Highlander in the system for a given time period.
Scenario: Inserting a new Higlander for a time period already taken by another
Given there is a Highlander Adam in the system for time period 1820-1900
When I insert a Higlander Bert for time period 1800-1900
Then the System raises Error Code "ONLY1"
Scenario: Inserting a new Higlander for a free time period
Given there is a Highlander Adam in the system for time period 1820-1900
When I insert a Higlander Bert for time period 1901 - 1902
Then the System raises no Error
My question ist about the error code (ONLY1
) in the first scenario. Currently, our system raises many errors, but we do not have
a simple way to identify a specific error condition.
Our System ist more than 15 years old. Isn't it funny that we havn't found this to be an issue for so many years?
I find it great that BDD makes it so obvious that we need a clear, shared language to identify our error messages.
Some of my colleagues argue that there is no need for an error code. This means that we have to write the assertion like this:
Then the System shows the error "There can only be 1 Highlander for a given time period."
This makes me cringe, because
- The test will break if we later decide to change the text to something else
- The test will only be successful on the english version of the software (we support several languages)
- An error Code is great for finding information in a knowledge base or in suppoert tickets.
Of course, we should show the error code and a readable description of the error in the users language, but in the test spec, I would prefer to only mention the error code.
How do you test for errors? do you use codes or exceptions or just plain text?
Best Regards Mat