-1

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.

M21B8
  • 1,867
  • 10
  • 20

1 Answers1

0

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.

Vincent F
  • 6,523
  • 7
  • 37
  • 79
  • the default does have a real name, but its only in the actual front end page (our tests aren't hitting the UI layer), so the actual underlying data for the default is just a blank string (essentially the ui says if not blank, display the value, otherwise display xyz.png). – M21B8 Jun 29 '15 at 08:55
  • some will disagree, but in my opinion, even minor logic like this shouldn't be in the UI. Since anyway you need to have some logic in controller to return a String (whether a real name or empty), you may as well return the actual default value from your backend. This way your logic for all cases is at the same place, not scattered between UI and backend. – Vincent F Jun 29 '15 at 18:52