【发布时间】: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