如何使用 Main.run 方法生成 Cucumber 报告?

How to generate Cucumber Report using Main.run method?

我正在使用 Cucumber Java

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>6.1.1</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>6.1.1</version>
    </dependency>

我没有使用 Cucumber Options 配置要使用的步骤或功能。我正在使用 Main.run 方法

String feature = "/resources/service1/feature1.feature"
Main.run(new String[]{"--glue", "example.aop.testing.steps", feature}
            , Thread.currentThread().getContextClassLoader())

一切正常,但我想生成一份包含结果的报告。我正在阅读它并配置它我需要使用 Cucumber Options,像这样:

@RunWith(Cucumber.class) 
@Cucumber.Options(format = {"pretty", "html:target/cucumber"}) 

public class runTest { }

如何使用该方法配置它?

您可以在添加胶水和功能的同一个数组中使用其他选项,如下所示

 String[] commonOptions = {
                "--glue",
                "com.test.automation.stepdefinitions",
                "--tags",
                "@foo",                
                "--plugin",
                "pretty",
                "--plugin",
                "html:"+reportFolderPath+"/html",
                "--plugin",
                "json:"+reportFolderPath+"/cucumber.json",
                FEATURE_FILE_PATH
        };