【问题标题】:Cannot execute maven test from command line using tags?无法使用标签从命令行执行 maven 测试?
【发布时间】:2019-01-28 21:18:31
【问题描述】:

当我运行以下命令时:

mvn test -Dcucumber.options="--tags @UserAuthentication"

然后我得到以下错误:

Unknown lifecycle phase 
".options=src/test/java/Feature --tags @@UserAuthentication". 
You must specify a valid lifecycle phase or a goal in the format 
<plugin-prefix>:<goal> or 
<plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>

我的 POM 文件如下:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.test.org 测试 0.0.1-快照

      <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <maven.compiler.source>1.8</maven.compiler.source>
          <maven.compiler.target>1.8</maven.compiler.target>
        </properties>

      <build>
          <pluginManagement>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
              </plugin>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.8.0</version>
              </plugin>
            </plugins>
          </pluginManagement>
       </build>

      <dependencies>
          <dependency>
              <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-java</artifactId>
              <version>3.7.1</version>
          </dependency>
          <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.12</version>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-java</artifactId>
              <version>1.2.5</version>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-jvm-deps</artifactId>
              <version>1.0.5</version>
              <scope>provided</scope>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-junit</artifactId>
              <version>1.2.5</version>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>com.vimalselvam</groupId>
              <artifactId>cucumber-extentsreport</artifactId>
              <version>3.0.2</version>
          </dependency>
          <dependency>
              <groupId>com.aventstack</groupId>
              <artifactId>extentreports</artifactId>
              <version>3.1.2</version>
          </dependency>       
      </dependencies>  </project>

我的跑步者班级如下:

  @RunWith(Cucumber.class)
    @CucumberOptions(
            features ="src/test/java/Feature",
            glue= "stepDefinitions",
            tags= {"@Pagination,@UserAuthentication"},
            plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"}, 
            monochrome = true)

    public class RunnerTest {
        @AfterClass
        public static void writeExtentReport() {
            Reporter.loadXMLConfig(new File("config/report.xml"));
        }
    }

我不知道使用标签从命令行运行测试的目标是什么。

【问题讨论】:

  • 你找到解决方案了吗?

标签: java maven selenium-webdriver junit cucumber


【解决方案1】:

根据https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html,有两种方法可以将“系统属性”传递给surefire(mvn test)执行:

  1. 通过configuration/systemPropertyVariables
  2. ...或已弃用的 configuration/systemProperties 元素。

你没有使用这些。

还请注意,只有“字符串类型”的属性才能以这种方式传递。 ...并且:

部分系统属性必须在分叉虚拟机的命令行中设置,在虚拟机启动后无法设置。这些属性必须添加到 Surefire 插件的 argLine 参数中。例如,&lt;argLine&gt;-Djava.endorsed.dirs=...&lt;/argLine&gt;

因此,在您的情况下,最安全的(假设分叉执行)是:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <argLine>-Dcucumber.options="--tags @UserAuthentication"</argLine>
    </configuration>
</plugin>

...也可以:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <systemPropertyVariables>
            <cucumber.options>--tags @UserAuthentication</cucumber.options>
        </systemPropertyVariables>
    </configuration>
</plugin>

【讨论】:

  • 谢谢@xerx593,我尝试了您的解决方案,但仍然遇到同样的错误。
  • 正在运行 mvn test(没有其他参数)!?
猜你喜欢
  • 2020-10-30
  • 2013-12-12
  • 1970-01-01
  • 2021-11-19
  • 2018-08-16
  • 2018-04-11
  • 2021-01-22
  • 2014-04-23
  • 1970-01-01
相关资源
最近更新 更多