Cucumber 如何在空手道中通过命令重置黄瓜报告的env

Cucumber 如何在空手道中通过命令重置黄瓜报告的env,cucumber,karate,gherkin,cucumber-junit,Cucumber,Karate,Gherkin,Cucumber Junit,我有一个空手道跑步者文件来生成报告 public void genrateFinalReport() { System.setProperty("karate.env", "pre_production"); // ensure reset if other tests (e.g. mock) had set env in CI Results results = Runner.parallel(getClass(), 1); generateRe

我有一个空手道跑步者文件来生成报告

public void genrateFinalReport() {
        System.setProperty("karate.env", "pre_production"); // ensure reset if other tests (e.g. mock) had set env in CI
        Results results = Runner.parallel(getClass(), 1);
        generateReport(results.getReportDir());
        assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
    }
在这里,我设置了预生产环境

我想通过命令行更改或修改环境

要通过命令行更改环境,我使用下面的命令

mvn test -Dkarate.env=production -Dtest=PcadSanityTestReport
但默认情况下,pre_生产环境正在通过

com.intuit.karate - karate.env system property was: pre_production

有人能帮助我在命令行中传递env吗?或者我需要为不同的env创建不同的运行程序吗?我不知道我是否理解。您可以使用

System.setProperty("karate.env", "pre_production");
就在您启动测试之前,您希望值会有所不同吗

编辑: 因为您似乎想要
env
的默认值,所以应该在karate-config.js中这样做

var env = karate.env;
//here, you can override env with a default value if the value isn't an authorized one :
if (env != "pre_production" && env != "production"){
    env = "pre_production";
}

是,我要覆盖该值。如何通过命令行覆盖值命令行工作。只需删除
System.setProperty(“karate.env”、“pre_production”)
我还更新了我的帖子,向您展示了如果
env
不是授权值,如何直接在
karate config.js
中使用默认值