Question

I am having a problem with writing a test scenario checking a validity of stations that will be added to a database. Can anyone provide me with an example showing how to write it correctly. Somehow I feel that 'Scenario outline' is not the correct way...

'stations' and 'new_stations' are complex types I want to have 'stations' as already defined and check if each one of 'new_stations' can be added.

Scenario Outline: 
    Given We have <stations>
    And We are trying to add a station of the <new_stations> having the same id, the same name or the same code
    Then we should not be able to add it


# <stations>
        | Id | Code | Name     | Validity                      |
        | 1  | 1    | City 1   | from 2013-01-01 to 2013-04-01 |
        | 2  | 2    | City 2   | from 2013-03-15 to 2013-05-01 | 

# <new_stations>
        | Id | Code | Name   | Validity                      |
        | 1  | 234  | City 4 | from 2013-03-01 to 2013-07-01 |
        | 3  | 5    | City 1 | from 2013-03-01 to 2013-07-01 |
        | 4  | 2    | City 3 | from 2012-03-15 to 2013-07-15 | 

So none of 'new_stations' should be added

  • Id 1 because its Id is not unique
  • Id 3 because its Name is not unique
  • Id 4 because its Code is not unique
Was it helpful?

Solution

I think you might be mixing up your manys.

A scenario outline is used to describe the same scenario, but in a parameterised way so that values are injected in turn. That looks like the second table you have

But your example reads like you need to inject many rows of data all at once for the known stations, so it will become (see tables)

Scenario Outline: 
  Given We have 
    | Id | Code | Name     | Validity                      |
    | 1  | 1    | City 1   | from 2013-01-01 to 2013-04-01 |
    | 2  | 2    | City 2   | from 2013-03-15 to 2013-05-01 | 
  And We are trying to add a station <Id>, <Code>, <Name>, <Validity> 
  Then we should not be able to add it

Examples:
    | Id | Code | Name   | Validity                      |
    | 1  | 234  | City 4 | from 2013-03-01 to 2013-07-01 |
    | 3  | 5    | City 1 | from 2013-03-01 to 2013-07-01 |
    | 4  | 2    | City 3 | from 2012-03-15 to 2013-07-15 | 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top