【问题标题】:maven-surefire-plugin inclusion of Single test is not workingmaven-surefire-plugin 包含单一测试不起作用
【发布时间】:2019-03-07 06:39:08
【问题描述】:

要从 Maven pom.xml 执行单个测试,我们可以从 maven surefire 插件执行它。

http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <includes>
                    <include>App.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

但是,它现在不起作用。有什么东西要申报吗?我记得,在我执行它的几个月前,它就奏效了。

控制台:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< mavenSampleProject01:mavenSampleProjects >--------------
[INFO] Building mavenSampleProjects 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenSampleProjects ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Desktop-pc\eclipse-workspace\mavenSampleProjects\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mavenSampleProjects ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mavenSampleProjects ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Desktop-pc\eclipse-workspace\mavenSampleProjects\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mavenSampleProjects ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ mavenSampleProjects ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.371 s
[INFO] Finished at: 2018-10-02T11:58:27+05:30
[INFO] ------------------------------------------------------------------------

【问题讨论】:

  • 确保目录结构符合表达式。据我所知,使用此表达式,文件必须位于 sry/test/java 的根级别(意味着没有包)。
  • @bish 如果我将其定义为: src/main/java/pg01/App.java 而不是它不起作用。
  • @glytching 我也试过了,但它不起作用。
  • 如果你想执行一个单一的测试,这可以通过像mvn -Dtest=FirstTest test这样的命令来实现,不需要为这些事情更改pom文件。
  • @khmarbaise 谢谢。但是,我在 Jenkins 中执行,来自 POM.XML

标签: java maven selenium pom.xml maven-surefire-plugin


【解决方案1】:

我发现,Maven 测试只从 src/test/java 包中运行它

不考虑从 src/main/java 运行

如果需要考虑src/main/java,我们必须添加&lt;testSourceDirectory&gt;元素

<build>
    <testSourceDirectory>src/main/java</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <includes>
                    <include>**/app.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

【讨论】:

    【解决方案2】:

    将以下插件添加到您的 POM 文件中。

    <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.19.1</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <forceJavacCompilerUse>true</forceJavacCompilerUse>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
    

    【讨论】:

      【解决方案3】:

      您需要提供完整的限定类名以通过surefire 插件包含它。 https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

      或者,您可以使用“**/*App.java”之类的正则表达式

      【讨论】:

      • **/*App.java 不是正则表达式模式。就是所谓的ant风格的路径表达式
      猜你喜欢
      • 2022-07-14
      • 2014-01-07
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 2022-01-14
      • 2019-07-14
      相关资源
      最近更新 更多