Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to input null-value into specflow step definition table

How can I input a null value in Specflow through a table?

Let's look at an overly simplistic example:

When a tire is attached to a car
| CarId | TireModel      | FabricationDate | Batch |
| 1     | Nokian Hakka R | 2015-09-1       |       |

The empty string in the Batch column is interpreted as text by specflow and as such, empty string. Is there a special syntax to mark that column as null?

like image 365
Tuukka Haapaniemi Avatar asked Oct 02 '15 13:10

Tuukka Haapaniemi


1 Answers

From SpecFlow 3 on-wards, in your Steps class, you can just put the following code. And in the feature file just put null value like this. Now when you use the CreateSet function then it will be deserialized correctly.

Id | Value
1  | <null> 

[Binding]
public static class YourStepClass
{
    [BeforeTestRun]
    public static void BeforeTestRun()
    {
        Service.Instance.ValueRetrievers.Register(new NullValueRetriever("<null>"));
    }
}
like image 117
Varun Sharma Avatar answered Oct 21 '22 11:10

Varun Sharma