在没有JUnit的情况下运行Cucumber的替代方法? [英] Alternate way to run Cucumber without JUnit?

查看:230
本文介绍了在没有JUnit的情况下运行Cucumber的替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有其他方法可以在没有Junit的情况下运行黄瓜。

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

是否可以将黄瓜作为Java应用程序运行...就像我创建一个main ()方法并控制那里的所有步骤定义?

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?

任何帮助都很棒

推荐答案

可以从命令行调用黄瓜JVM。所以下面的答案适用于可以从命令行调用的任何Java代码,而不仅仅适用于Cucumber JVM(它只是另一个Java组件/库)。

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).

你可以通过静态方法调用从您自己的main方法(或任何其他方法)调用任何Java main 方法。我们只需要模拟命令行参数的传递方式。

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.

所以如果你能从命令行调用Cucumber JVM:

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

这是一个如何使用您自己的Java代码执行此操作的示例:

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);
    }
}

这篇关于在没有JUnit的情况下运行Cucumber的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆