0

I've written a CucumberJVM test harness and a large set of feature files to test my application. Some of these tests can take 10 to 20 minutes to run which means that the test harness appears to hang for long periods of time.

To give my end users some confidence that the machine hasn't locked up, what I'd like to do at the start of each Scenario is to print the Scenario name. I know that the @Before can be used to define a glue method that will be executed before each test starts. So my question is:

"How can I get the Scenario name in a @Before annotated method"

Stormcloud
  • 2,065
  • 2
  • 21
  • 41

1 Answers1

1

I assume you are using the junit runner, so here's a simple example.

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "classpath:features/something.feature",
        format = "com.blah.PrintingFormatter",
        glue = "com.blah.steps")
public class CucumberTest {

}

Then your PrintingFormatter should implement the gherkin.formatter.Formatter interface, specifically the startOfScenarioLifeCycle method. Slap your println in there and you're good to go.

benkiefer
  • 739
  • 6
  • 10
  • Thanks for answering :-) (It's been almost 6 months and I'd given up hope). Just for anybody else who might be looking at this answer: method feature(Feature f) can be used to display the feature file name. method scenario(Scenario s) can be used to display the scenario name. Two or the price of 1! – Stormcloud Jun 20 '14 at 15:19
  • No problem. My suite was about two minutes long, and I wasn't willing to go without some form of feedback. I can't imagine what it would be like after 20 minutes. Glad this was able to help. – benkiefer Jun 29 '14 at 19:32