Skip to content

Instantly share code, notes, and snippets.

@restagner
Created February 17, 2012 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save restagner/1850089 to your computer and use it in GitHub Desktop.
Save restagner/1850089 to your computer and use it in GitHub Desktop.
Example of scenario outlines, scenarios and tags
@feature_1
Feature: Feature one
Scenario: A
Given a step in A
When an action in A
Then the expected outcome is X
@feature_2
Scenario Outline: B
Given a step in C
When an action in B
Then the outline's expected outcome is <result>
Examples:
| result |
| Y |
| W |
Feature: Feature 2
@feature_2
Scenario: C
Given a step in C
When an action in C
Then the expected outcome is Z
package org.stag.hello;
import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
@RunWith(Cucumber.class)
@Feature(tags = {"@feature_1, @feature_2"}, value = "features/")
public class HelloTest {
}
package org.stag.hello;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
public class StepDefsForFeature_1 {
@Given("^a step in A$")
public void aStepInA() {
printMessage("Inside GIVEN step A");
}
@When("^an action in A$")
public void anActionInA() {
printMessage("Inside WHEN step A");
}
@Then("^the expected outcome is X$")
public void theExpectedOutcomeIsX() {
printMessage("Inside THEN step X");
}
@When("^an action in B$")
public void anActionInB() {
printMessage("Inside WHEN step B");
}
@Then("^the outline's expected outcome is (.*)$")
public void theExpectedOutcomeIsY(String result) {
printMessage("Inside THEN step " + result);
}
private void printMessage(String msg) {
System.out.println("[" + StepDefsForFeature_1.class + "]: " + msg);
}
}
package org.stag.hello;
import cucumber.annotation.Before;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
public class StepDefsForFeature_2 {
@Before("@feature_2")
public void setup() {
printMessage("Inside tagged BEFORE hook -- tag = @feature_2");
}
@Given("^a step in C$")
public void aStepInC() {
printMessage("Inside GIVEN step C");
}
@When("^an action in C$")
public void anActionInC() {
printMessage("Inside WHEN step C");
}
@Then("^the expected outcome is Z$")
public void theExpectedOutcomeIsZ() {
printMessage("Inside THEN step Z");
}
private void printMessage(String msg) {
System.out.println("[" + StepDefsForFeature_2.class + "]: " + msg);
}
}
@restagner
Copy link
Author

EXPECTED OUTPUT

[class org.stag.hello.StepDefsForFeature_1]: Inside GIVEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step X
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step Y
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step W
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside WHEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside THEN step Z

ACTUAL OUTPUT

[class org.stag.hello.StepDefsForFeature_1]: Inside GIVEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step X
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step Y
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step W
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside WHEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside THEN step Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment