简体   繁体   English

如何使用 cucumber 测试创建可执行的 jar 文件?

[英]how to create executable jar file with cucumber tests?

My service create an executable jar by gradle.我的服务通过 gradle 创建了一个可执行的 jar。 When i create and run my jar (java -jar file.jar) i recive error:当我创建并运行我的 jar (java -jar file.jar) 我收到错误:

no main manifest attribute, in "file.jar"

because i don't have main_class.因为我没有 main_class。

I created main method:我创建了主要方法:

public static void main(final String[] args) throws Throwable {
String[] arguments = {"--plugin", "html:build/reports/cucumber", "src/test/resources/features", "--glue", "src/test/java/steps"};
cucumber.api.cli.Main.main(arguments);

} }

and My program founds the features but doesn't found glue code.我的程序找到了功能但没有找到胶水代码。

Could someone help me with this problem?有人可以帮我解决这个问题吗? Thank you in advance.先感谢您。

The value for the glue option should be a java classpath. 胶水选项的值应为java类路径。 And the feature files should be the last option. 功能文件应该是最后的选择。

{"--plugin", "html:build/reports/cucumber", "--glue", "steps", "src/test/resources/features"}

The below code worked for me to execute the cucumber tests from runnable jar with test frame work as TestNG.下面的代码对我有用,可以从可运行的 jar 执行 cucumber 测试,测试框架为 TestNG。

Executing jar: java -jar ProductsAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar执行 jar: java -jar ProductsAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar

import io.cucumber.core.cli.Main;
public static void main(String args[]) throws Throwable {
    try {
        Main.main(new String[] { 
    

        "-g","com.sadakar.cucumber.common",
        "-g","com.sadakar.cucumber.runner",
                    
        "classpath:features", 
        
        "-t","@SmokeTest",
        
                
        "-p", "pretty", 
        "-p", "json:target/cucumber-reports/cucumber.json", 
        "-p", "html:target/cucumber-reports/cucumberreport.html",
        
        "-m"
    }
    );
} catch (Exception e) {
        e.printStackTrace();
        System.out.println("Main method exception : " + e);
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM