Conditional Inputs?

123 views Asked by At

I'm trying to write a cucumber test for part of our application (I'm completely new to cucumber, and writing acceptance tests really), and I have a step in the test, which I want to do one of 2 different things. I want it to either check for a specific value, or check for a system default value.

This is what I came up with

Scenario Outline: English News
  Given with the locale is set to '<language>'
  When a user views the page
  Then they see the <image> image


Examples:
  | language | image        |
  | en-gb    | default      |
  | fr       | "french.png" |

This then hits one of 2 different step definitions,

@And("^they see the default image$")
public void defaultImage() throws Throwable {
    // check for system default
}

@And("^they see the \"(.*)\" image$")
public void customImage(String image) throws Throwable {
    // check for specific value from the input
}

Is this the correct way to do this? My TL has suggested that I should actually only have the one step def, and pass "default" as the input, and then do a conditional check inside the step def, like this:

@And("^they see the \"(.*)\" image$")
public void checkImage(String image) throws Throwable {
  if ("default".equals(image)){
    // check for system default
  } else {
    // check for specific value from the input
  }
}

Which is the correct way to do this? Any help is greatly appreciated.

1

There are 1 answers

2
Vincent F On

your default image must have a real name, right ? so why not validating its real name ? because "default" could be anything so not everyone may understand the same thing.

If you do this, indeed you need only one step def. I wouldn't put an if check, I would assert the real name. You can maybe add a comment in your example table saying that the first value is the default, so that it's clear for everyone in your team.