如何从Java代码而不是从JUnit Runner运行黄瓜功能文件 [英] How to run cucumber feature file from java code not from JUnit Runner

查看:107
本文介绍了如何从Java代码而不是从JUnit Runner运行黄瓜功能文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Java代码运行黄瓜功能文件.

I want to run cucumber feature file from java code.

当前,我们正在运行JUnit Runner形式

currently we are running form JUnit Runner

package com.compareglobalgroup.testscript;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

    @CucumberOptions(features = { "src/test/resources/feature/BB" }, glue = { "com.compareglobalgroup.stepdefs.BB",
        "com.compareglobalgroup.cucumber.hooks" }, plugin = {
                "json:cucumberreport/json/cucumberreport.json" }, tags = { ""
                        + "@Test" })
    public class TestRunnerBB extends AbstractTestNGCucumberTests {

}

我不想使用它,而是想使用Java程序运行它,因为我想在运行时从命令行或jenkins传递标签.

I don't want to use this instead I want to run this using java program because I want to pass tags at run time from command line or jenkins.

推荐答案

调用

Call the static main method of Main class in the package cucumber.api.cli that corresponds to running cucumber from the command line.

public static void main(String[] args) throws Throwable {

    Main.main(new String[]{"-g", "classpath to step definition file", "Full path to feature file"});

          // My stepdefinition is inside java package at cucumber.sample.test
          // My feature file is inside src/test/resources/features/featurefile.feature

        } 

对于其他参数,例如标签或插件,请使用"-t","@Tags". 重要的特征文件路径必须是最后一个选项.

For additional parameters like tags or plugin use "-t","@Tags". Important the feature file path has to be the last option.

顺便说一句-在您的示例中,您正在使用TestNG黄瓜浇头.

BTW - In the your example you are running with a TestNG cucumber runner.

这篇关于如何从Java代码而不是从JUnit Runner运行黄瓜功能文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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