burki
burki

Reputation: 7005

Citrus-Cucumber: Can I run a single Cucumber Scenario?

I have a Cucumber feature file with a bunch of Scenarios to execute Citrus integration tests (Citrus-Cucumber integration). I can run all Scenarios at once in IntelliJ or through Maven.

Works perfect, but is it possible to run a single Scenario in IntelliJ or through Maven?

In IntelliJ I found a Cucumber plugin that gives me this option, but after fixing lots of NoClassDefFound errors with dependency tricks, it fails because it does not respect the Citrus project files such as citrus-application.properties.

Upvotes: 0

Views: 607

Answers (1)

burki
burki

Reputation: 7005

Answer to myself: Yes, I can.

According to the Cucumber docs, it uses tags to (what a surprise) tag scenarios. Tags begin with the @ symbol and one can set any number of tags on a Feature or Scenario.

Example:

@Test123
@Important
Scenario: My awesome Scenario
  Given ...
  When ...
  Then ...

@Test456
Scenario: My other Scenario
  Given ...
  When ...
  Then ...

With these tags in place, I can "select" scenarios to execute based on tags. For example to execute all important Scenarios I use the tag @Important.

cucumber --tags @Important

Since I execute my tests through a Citrus class, I have to pass the tags to execute in the CucumberOptions of my test class.

@RunWith(Cucumber.class)
@CucumberOptions(
        strict = true,
        glue = { "com.consol.citrus.cucumber.step.runner.core" },
        plugin = { "com.consol.citrus.cucumber.CitrusReporter" },
        tags = { "@Important" }
)
public class RunCucumberTests {
}

It is not super-convenient, to edit the test class metadata every time, but it works.

Upvotes: 2

Related Questions