-Dcucumber.options 被 mvn 测试忽略 [英] -Dcucumber.options ignored with mvn test

查看:31
本文介绍了-Dcucumber.options 被 mvn 测试忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mvn test";运行黄瓜测试,但是当我尝试在命令行上传递选项时-Dcucumber.options=...,选项被忽略,而使用运行器类中@CucumberOptions 中指定的选项.例如,如果我只是尝试显示 cucumber 帮助,它会忽略它并运行测试:

I'm using "mvn test" to run cucumber tests, but when I try to pass options on the command line with -Dcucumber.options=..., the options are ignored and the ones specified in @CucumberOptions in the runner class are used instead. For example, if I just try to display cucumber help, it ignores it and just runs the tests:

C:MavenArchCukeuntitled>mvn test -Dcucumber.options="--help"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.example:untitled >------------------------
[INFO] Building untitled 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ untitled ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:MavenArchCukeuntitledsrcmain
esources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ untitled ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ untitled ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ untitled ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:MavenArchCukeuntitled	arget	est-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ untitled ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.example.steps.CucumberTestRunner

Scenario: Add two numbers # features/arith.feature:4
  Given A Calculator      # org.example.steps.ArithSteps.aCalculator()
  When I add 2 and 2      # org.example.steps.ArithSteps.iAddAnd(int,int)
  Then I get 4            # org.example.steps.ArithSteps.iGet(int)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.253 s - in org.example.steps.CucumberTestRunner
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.815 s
[INFO] Finished at: 2020-11-05T10:51:50-08:00
[INFO] ------------------------------------------------------------------------

C:MavenArchCukeuntitled>

这是我的跑步者课

package org.example.steps;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"classpath:features"},
        plugin = {"pretty"}
)
public class CucumberTestRunner {
}

这是我的 pom.xml.

and this is my pom.xml.

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>untitled</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>untitled</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <junit.version>4.13</junit.version>
    <cucumber.version>6.8.0</cucumber.version>
    <maven.compiler.version>3.8.1</maven.compiler.version>
    <maven.surefire.version>2.22.2</maven.surefire.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
    </dependency>

    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>${cucumber.version}</version>
    </dependency>

    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit</artifactId>
      <version>${cucumber.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven.compiler.version}</version>
        <configuration>
          <encoding>UTF-8</encoding>
          <source>${java.version}</source>
          <target>${java.version}</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.version}</version>
        <!-- Include our runner class or 'mvn test' won't work; name doesn't match default template.
             See https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html -->
        <configuration>
          <includes>
            <include>CucumberTestRunner.java</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

我尝试了 surefire 插件的 3.0.0-M5 版本而不是 2.22.2,结果相同.我在这里做错了什么?

I tried version 3.0.0-M5 of the surefire plugin instead of 2.22.2, with the same results. What am I doing wrong here?

推荐答案

cucumber.options 属性已被弃用并删除.您必须将每个选项作为单个属性传递.

The cucumber.options property was deprecated and removed. You have to pass each option as a single property.

mvn test -Dcucumber.filter.tags='@smoke and not @ignore'

https://github.com/cucumber/cucumber-jvm/blob/main/release-notes/v5.0.0.md#property-based-options

这篇关于-Dcucumber.options 被 mvn 测试忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆