[JVM] Null values in DataTables

72 views
Skip to first unread message

s.kem...@findologic.com

unread,
Sep 9, 2016, 5:00:52 PM9/9/16
to Cukes
Hello everybody!

I am using Cucumber for testing a search engine,
but in some cases I have the problem that it is required to declare
null values. My solution is to use an "<empty>" tag.

Here are my questions:

Is there a better way to do this (Maybe something that is provided by cucumber)?
Is this conform with the Cucumber guidelines?
Or is my solution completely against the mind of Cucumber?

The background for this is a little complex but i try to explain it:

Basically I am searching for products that need to be defined first.
Each item can have several parameters.
Therefore i use a DataTable. My step looks as the following:

Given items with parameters
   
| name      | price  | attributes |
   
| product 1 | 100.99 | color=red  |
   
| product 2 | 30.00  | color=blue |


There are many more parameters that can be set.
All fields are optional and will be default values if not set.
If a parameter is not set or an empty field the StepDefinition will
give it a default value out of a pre defined Hashmap.

Sometimes one item needs more fields than another which might look like this:

Given items with parameters
   
| name      | price  | attributes |
   
| product 1 | 100.99 |            |  <--- this field will have a default value
   
| product 2 | 30.00  | color=blue |

Since it does not make sense to write an empty attribute for product 1
empty fields are ignored in the StepDefinition and will have a default value.
However, sometimes it does make sense to overwrite the default value with an empty String.
E.g. when I want to make sure that there is really nothing in this field.
In other cases it is required that a field of the item is set null.
To signalize this i use an "<empty>" tag. If the field with this tag is
a String, it will be an empty String , otherwise (I also use Doubles, Maps, ...) the value is set null.

This might look like the following:

Given items with parameters
   
| name      | price  | attributes |
   
| product 1 | 100.99 | <empty>    |  <--- I want to make sure that there is no default value in this field
   
| product 2 | 30.00  | color=blue |

I know that the steps should be as simple as possible, but it in my
case it really does not make sense to write a step for each combination
of parameters. In addition all items and their parameters must be declared
at once (this is a requirement of the underlying API).


I also use the tag in another step:
When I want to check if the returned result of the search has the right parameters.

When searching for "product"
Then the found items should have the following parameters
   
| label     | relevance |
   
| product 1 | <empty>   |

In this case the step checks if the relevance parameter of the returned item is null.
I know that I could just write step for each combination of parameters and for each item,
but again this does not make sense since the result set contains many items with many more parameters
than in the example.

Thanks & Regards,
Stefan
Reply all
Reply to author
Forward
0 new messages