【问题标题】:Cucumber Command Line黄瓜命令行
【发布时间】:2020-09-04 21:24:17
【问题描述】:

我正在尝试通过使用此代码进行黄瓜命令行调用来运行不同的测试

public class RunTest {
    public RunTest(String test){
        System.out.println("you found me");        System.setProperty("protocol","https");
        String[] argv = {"-p", "json:cucumber-report.json", "-g", "Otto.CatalogTests", "classes/"+ test +".feature"};
        main(argv);
    }
}

但是我收到了这个错误信息:

Exception in thread "main" java.lang.NullPointerException
        at io.cucumber.messages.Messages$Meta$Builder.setProtocolVersion(Messages.java:6186)
        at io.cucumber.core.runtime.CucumberExecutionContext.emitMeta(CucumberExecutionContext.java:59)
        at io.cucumber.core.runtime.CucumberExecutionContext.startTestRun(CucumberExecutionContext.java:47)
        at io.cucumber.core.runtime.Runtime.run(Runtime.java:71)
        at io.cucumber.core.cli.Main.run(Main.java:76)
        at io.cucumber.core.cli.Main.main(Main.java:33)
        at Otto.CommandLine.RunTest.<init>(RunTest.java:16)
        at Otto.CommandLine.ArgumentHandler.executeArguments(ArgumentHandler.java:63)
        at Otto.CommandLine.ArgumentHandler.<init>(ArgumentHandler.java:28)
        at Otto.CommandLine.Main.main(Main.java:28)

当您单击此链接时:Messages.java:6186 您会看到以下代码:

public Messages.Meta.Builder setProtocolVersion(String value) {
    if (value == null) {
        throw new NullPointerException();
    } else {
        this.protocolVersion_ = value;
        this.onChanged();
        return this;
    }
}

看来我没有设置我的协议版本,我该怎么做?

我尝试了System.setProperty("protocol","https");,但没有奏效,我也不知道哪种协议是最佳实践。

感谢您的所有帮助。

【问题讨论】:

    标签: java automated-tests cucumber command-line-arguments


    【解决方案1】:

    您似乎正在使用 Cucumber v6.0.0-RC2。而且看起来您正在将 Cucumber 着色到您的项目中。在这种情况下,您必须将实现和规范版本添加到清单文件中。如果您碰巧使用 maven,您可以使用 maven-jar-plugin

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
            <archive>
                <manifest>
                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                </manifest>
            </archive>
        </configuration>
    </plugin>
    

    Gradle 应该有自己的等价物。

    【讨论】:

      猜你喜欢
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 2021-11-19
      • 2019-10-16
      • 1970-01-01
      相关资源
      最近更新 更多