2

I have a bit of a special situation. Basically I have a unit test, annotated with @Test, and inside that test I need to execute a Cucumber JVM test class.

Why? Long story. Something to do with classloaders and RoboGuice, it's not very important but it does impose limits on what I can and cannot do.

Here's the test method:

@Test
public void runCucumberFeature() throws Exception {
    Cucumber cucumber = new Cucumber(MyCucumberTest.class);
    cucumber.run(new RunNotifier());
}

MyCucumberTest is a class I have created, and annotated like this:

//@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber"}, strict=true)
public class MyCucumberTest {
    // Empty, as required by Cucumber JVM
}

Why have I commented out the @RunWith annotation? Because if I don't, the Cucumber test runner will pick up the test and run it, which I don't want because I am running the test manually.

The problem is that the above doesn't work. It looks like Cucumber is finding the feature files, it is verifying that MyCucumberTest contains the @Givens etc, it even prints out the test as if it was running it.

But it doesn't. No code is executing inside the @Given, @When and @Then methods. I'm not sure why this is, but I have a vague idea that the Cucumber JVM test runner doesn't want to execute the code because the class isn't annotated with @RunWith.

Can anyone help?

1 Answer 1

2

I can't provide the solution you're looking for, but....

... have you considered tagging the test that you want to run manually (e.g. with @Manual)?

Then you could uncomment your @RunWith annototation and exclude the manual test by adding --tags ~@Manual to your Cucumber-JVM invocation.

In your manual JUnit invocation you could add --tags @Manual

Sign up to request clarification or add additional context in comments.

2 Comments

I did not know there was a @Manual tag. It might help. Thanks for the suggestion, it's the best so far :-)
The tags are user defined - use tags that make sense to you. You can apply multiple tags to a scenario, which makes it possible to build up test suites for specific purposes (e.g. \@Regression, \@Defect_54321 etc.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.