我的测试也在 eclipse、mvn test、命令行中运行,但不在 jenkins 中运行。控制台中的 Maven Surefire 插件表示没有要运行的测试。我怀疑 Maven Surefire 插件无法选择测试。我的 POM 看起来像:
<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>groupid</groupId>
<artifactId>artifactiddemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<packaging>jar</packaging>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</plugins>
</build>
</project>
Jenkins 作业日志:
Executing Maven: -B -f C:\Program Files (x86)\Jenkins\workspace\Second_Job\pom.xml verify -Dcucumber.options=test/features/FirstDemo.feature -DskipTests=false
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< groupid:artifactiddemo >-----------------------
[INFO] Building artifactiddemo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ artifactiddemo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Program Files (x86)\Jenkins\workspace\Second_Job\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ artifactiddemo ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ artifactiddemo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Program Files (x86)\Jenkins\workspace\Second_Job\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ artifactiddemo ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.8.1:test (default-test) @ artifactiddemo ---
[INFO] No tests to run.
[INFO] Surefire report directory: C:\Program Files (x86)\Jenkins\workspace\Second_Job\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
我知道我缺少一些东西来包含测试在surefire插件的东西..但他们在本地eclipse或mvn test命令上运行顺利。提前致谢
最佳答案
您没有提供有关您的测试类(class)的任何信息。确保测试的类名与 patterns 之一匹配:
- “**/Test*.java” - 包括其所有子目录以及以“Test”开头的所有 Java 文件名。
- “**/*Test.java” - 包括其所有子目录以及所有以“Test”结尾的 Java 文件名。
- “**/*Tests.java” - 包括其所有子目录以及所有以“Tests”结尾的 Java 文件名。
- “**/*TestCase.java” - 包括其所有子目录以及所有以“TestCase”结尾的 Java 文件名。
关于java - Maven Surefire 插件未在 jenkins 中选择测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57336080/