在没有 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 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);
}
}
相关文章