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

huangapple go评论63阅读模式
英文:

How to generate Cucumber Report using Main.run method?

问题

我正在使用Cucumber for 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 { }

如何使用这种方法进行配置?

英文:

I am using Cucumber for Java

    &lt;dependency&gt;
        &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
        &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
        &lt;version&gt;6.1.1&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
        &lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
        &lt;version&gt;6.1.1&lt;/version&gt;
    &lt;/dependency&gt;

I am not using Cucumber Options to configure the step or feature to use. I am using Main.run method

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

Everything it's working find but I would like to generate a report with the result. I was reading about it and to configura it I need to use Cucumber Options, like this:

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

public class runTest { }

How can I configure it using that approach??

答案1

得分: 2

你可以在添加glue和feature的同一数组中使用其他选项,如下所示:

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

You can use other options in the same array you are adding your glue and feature like below

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

huangapple
  • 本文由 发表于 2020年7月31日 03:36:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63180172.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定