Alternate way to run Cucumber without JUnit?

亡梦爱人 提交于 2019-12-10 11:38:22

问题


Is there any alternate way to run the cucumber without Junit.

Is that any possible way to run cucumber as a Java application.. like if I create a main() method and control all step definitions over there?

Any help will be awesome


回答1:


The answer is out of date. The cucumber docs have this to say, "Running Cucumber

There are several ways to run scenarios with Cucumber-JVM:

  • JUnit Runner
  • CLI Runner
  • Android Runner
  • Third party runners "



回答2:


Cucumber JVM can be invoked from command line. So the answer below applies to any Java codes that can be invoked from command line, not just for Cucumber JVM (which is just another Java component/library).

You can invoke any Java main method from your own main method (or any other methods) through static method invocation. We just need to simulate how the command line arguments being passed.

So if you are able invoke the Cucumber JVM from command line:

java -jar cucumber-jvm.jar cucumber.api.cli.Main --strict --glue com.mycompany.glue --plugin pretty

This is an example how you can do that from your own Java code:

public class MyMainClass {
    public void main(String[] args) {
        String[] args = new String[] {
            "--strict",
            "--glue",
            "com.mycompany.glue",
            "--plugin",
            "pretty"
        };
        cucumber.api.cli.Main.main(args);
    }
}



回答3:


Cucumber is just another custom Junit runner. so can not have cucumber without Junit.



来源:https://stackoverflow.com/questions/16739347/alternate-way-to-run-cucumber-without-junit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!