0
votes

I am fairly new to Cucumber. I was experimenting with it by just creating few test features when I noticed the difference when running a single feature vs running the whole suite (from the IntelliJ).

I noticed that when I run single feature it runs using the cucumber-jvm option and in this case, the CucumberConfig(the blank class to define the runner and cucumber options) and the Runner is not utilized. However, when I run the whole suite it runs as a JUnit test and obviously, in this case, the Config class and the runner comes into the picture.

I confirmed this with the following sample code:

@RunWith(CustomRunner.class)
@CucumberOptions()
public class CucumberConfig {
    @BeforeClass
    public static void beforeClass()
    {
        System.out.println("This is run before Once: ");
    }

    @AfterClass
    public static void afterClass()
    {
        System.out.println("This is run after Once: ");
    }
}

CustomRunner

public class CustomRunner extends Cucumber {
        public CustomRunner(Class clazz) throws InitializationError, IOException {
            super(clazz);
            System.out.println("I am in the custom runner.");
        }

    }

Also, I understand that while running as cucumber-junit we can't pass specific feature to run as in cucumber-jvm. Correct me if I am wrong.

My doubt is, is this the default behavior or am I doing something wrong. And, if this is default how can I make cucumber to always use the Config file.

I'll appreciate if someone can provide some insight on this.

1
@MikeJRamsey56 Thanks. I know how to use CucumberOptions. My doubt is different. Its, can cucumber-jvm use the CucumberConfig file?user3275095
CucumberConfig file? Do you mean config/ cucumber.yml?MikeJRamsey56
@MikeJRamsey56 No not that. The blank config class we create with the runner annotation as given above.user3275095

1 Answers

1
votes

When you're using IntelliJ IDEA to run the tests, IDEA will use cucumber.api.Main to run the tests. As such it will ignore CucumberConfig neither will it run @BeforeClass nor @AfterClass, these are only used by the JUnit runner.