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

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

问题描述

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

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

是否有任何可能的方式将 cucumber 作为 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?

任何帮助都会很棒

推荐答案

可以从命令行调用 Cucumber 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 ma​​in 方法.我们只需要模拟命令行参数是如何传递的.

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天全站免登陆