【问题标题】:Select a different runner for cucumber.api.cli.Main?为 cucumber.api.cli.Main 选择不同的跑步者?
【发布时间】:2017-11-27 09:05:51
【问题描述】:

从黄瓜的命令行(cucumber.api.cli.Main)开始测试时是否可以定义/指定跑步者? 我这样做的原因是我可以在 Jenkins 中生成 xml 报告并将结果推送到 ALM Octane。

我有点继承了这个项目,它使用 gradle 来做 javaexect 并调用 cucumber.api.cli.Main 我知道在使用 JUnit runner + maven(或仅 JUnit runner)时可以使用 @RunWith(OctaneCucumber.class) 执行此操作,否则该标记将被忽略。我有带有该标签的自定义跑步者,但是当我从 cucumber.api.cli.Main 运行时,我找不到使用它运行的方法,我的标签就被忽略了。

【问题讨论】:

标签: jenkins gradle cucumber cucumber-jvm hp-alm


【解决方案1】:

@Grasshopper 的建议并不完全奏效,但它让我找到了正确的方向。

我没有将代码添加为插件,而是设法通过创建cucumber.api.cli.Main 的副本来“破解/加载”辛烷值报告器,使用它作为运行 cli 命令的基础并稍微更改@987654322 @ 方法并在运行时添加插件。需要这样做是因为插件在其构造函数中需要相当多的参数。可能不是完美的解决方案,但它让我能够保留我最初拥有的 gradle 构建过程。

public static byte run(String[] argv, ClassLoader classLoader) throws IOException {
    RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)));

    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);

    //====================Added the following lines ================
    //Hardcoded runner(?) class. If its changed, it will need to be changed here also
    OutputFile outputFile = new OutputFile(Main.class);
    runtimeOptions.addPlugin(new HPEAlmOctaneGherkinFormatter(resourceLoader, runtimeOptions.getFeaturePaths(), outputFile));
    //==============================================================

    runtime.run();

    return runtime.exitStatus();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2013-03-10
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 2015-09-09
    相关资源
    最近更新 更多