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

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

How to generate Cucumber Report using Main.run method?

问题

我正在使用Cucumber for Java。

  1. <dependency>
  2. <groupId>io.cucumber</groupId>
  3. <artifactId>cucumber-java</artifactId>
  4. <version>6.1.1</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>io.cucumber</groupId>
  8. <artifactId>cucumber-junit</artifactId>
  9. <version>6.1.1</version>
  10. </dependency>

我不是使用"Cucumber Options"来配置步骤或特性。我正在使用"Main.run"方法。

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

一切都正常工作,但我想生成一个带有结果的报告。我正在阅读有关此的信息,要配置它,我需要使用"Cucumber Options",就像这样:

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

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

英文:

I am using Cucumber for Java

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
  3. &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
  4. &lt;version&gt;6.1.1&lt;/version&gt;
  5. &lt;/dependency&gt;
  6. &lt;dependency&gt;
  7. &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
  8. &lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
  9. &lt;version&gt;6.1.1&lt;/version&gt;
  10. &lt;/dependency&gt;

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

  1. String feature = &quot;/resources/service1/feature1.feature&quot;
  2. Main.run(new String[]{&quot;--glue&quot;, &quot;example.aop.testing.steps&quot;, feature}
  3. , 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:

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

How can I configure it using that approach??

答案1

得分: 2

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

  1. String[] commonOptions = {
  2. "--glue",
  3. "com.test.automation.stepdefinitions",
  4. "--tags",
  5. "@foo",
  6. "--plugin",
  7. "pretty",
  8. "--plugin",
  9. "html:" + reportFolderPath + "/html",
  10. "--plugin",
  11. "json:" + reportFolderPath + "/cucumber.json",
  12. FEATURE_FILE_PATH
  13. };
英文:

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

  1. String[] commonOptions = {
  2. &quot;--glue&quot;,
  3. &quot;com.test.automation.stepdefinitions&quot;,
  4. &quot;--tags&quot;,
  5. &quot;@foo&quot;,
  6. &quot;--plugin&quot;,
  7. &quot;pretty&quot;,
  8. &quot;--plugin&quot;,
  9. &quot;html:&quot;+reportFolderPath+&quot;/html&quot;,
  10. &quot;--plugin&quot;,
  11. &quot;json:&quot;+reportFolderPath+&quot;/cucumber.json&quot;,
  12. FEATURE_FILE_PATH
  13. };

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:

确定