Specflow / Gherkin: how to deal with bad data

I'm new to Specflow, so here's:

For my example below. Should I be testing the bad? If I make a table you won't add a bad value. Thus, the code will be erroneous because it comes in as a bad type. I think I just need to know how others deal with checking that the user cannot enter bad data? (field names change due to confidential information) the requirement states:

Make sure the user cannot set a negative speed or more than 1. The speed range is 0.9999 to 0.

Make sure the user cannot enter a speed with more than four decimal places.

Given the lc does not exist  
    | Lc      |
    | Test90  |  
    | Test00  | 

    When I add a Lc  
    | Lc      | Somekind of ID|  Rate     |
    | Test90  | 2             |  0.9999   |
    | Test00  | 4             |  0        |

    Then the lc should be defined
    | Lc      | 
    | Test90  |
    | Test00  | 

      

+3


source to share


1 answer


It's a bit strange that you are testing 2 values ​​according to your test.

I would like to rewrite like this:



Scenario Outline: valid lc can be created
    Given the lc named <lc> does not exist  
    When I add a Lc named <lc> with Id <id> and rate <rate>
    Then the lc named <lc> should be defined
Examples:
        | Lc      | Id |  Rate     |
        | Test90  | 2  |  0.9999   |
        | Test00  | 4  |  0        |


Scenario Outline: Invalid lc cannot be created
    Given the lc named <Lc> does not exist  
    When I add a Lc named <Lc> with Id <Id> and rate <Rate>
    Then the lc named <Lc> should not be defined
    And an error should have been raised saying the rate was invalid
Examples:
        | Lc      | ID |  Rate     |
        | Test90  | 2  |  1.999    |
        | Test90  | 2  |  0.99999  |
        | Test90  | 2  |  -0.9     |
        | Test00Y | 4  |  6        |
        | Test00Y | 4  |           |

      

The step And an error should have been raised saying the rate was invalid

is obviously optional, but indicates that it is expected to happen due to the wrong speed.

+1


source







All Articles