Reputation: 3534
Is there any way to declare a variable in a feature file to then use in a cucumber test? Something like this:
myFile.feature
Given whenever a value is 50
myFile.java
@Given("^whenever a value is 50$")
public void testing(value) {
assertEqual(value, 50);
}
Honestly, I don't even know what this would look like. But I would love to not have to declare a value in both the feature file AND the Cucumber test. Thanks!
Upvotes: 1
Views: 8548
Reputation: 934
Yes you can! Write the Given-step in the feature.
Feature: foobar
Scenario: something
Given whenever a value is 50
Then run it as a JUnit test. You will see something like this in the console.
@Given("^whenever a value is (\\d+)$")
public void whenever_a_value_is(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Then you can copy+paste it and change it to:
@Given("^whenever a value is (\\d+)$")
public void whenever_a_value_is(int value) {
assertEquals(value, 50);
}
Upvotes: 3