【问题标题】:Maven surefire plugin not picking tests in jenkinsMaven surefire 插件没有在詹金斯中选择测试
【发布时间】:2019-12-11 15:33:36
【问题描述】:

我的测试也在 eclipse、mvn 测试、命令行中运行,但不在 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命令上运行顺利。提前致谢

【问题讨论】:

  • 检查并确保您的测试文件夹中有测试类,您可以在本地运行吗?

标签: java jenkins cucumber pom.xml maven-surefire-plugin


【解决方案1】:

您没有提供有关您的测试课程的任何信息。确保测试的类名与patterns 之一匹配:

  • “**/Test*.java” - 包括其所有子目录和所有以“Test”开头的 Java 文件名。
  • “**/*Test.java” - 包括其所有子目录和所有以“Test”结尾的 Java 文件名。
  • “**/*Tests.java” - 包括其所有子目录和所有以“Tests”结尾的 Java 文件名。
  • “**/*TestCase.java” - 包括其所有子目录和所有以“TestCase”结尾的 Java 文件名。

【讨论】:

  • 如果他们能够使用mvn test 运行测试,这不可能是问题...
猜你喜欢
  • 1970-01-01
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 2012-02-23
  • 2021-09-10
  • 1970-01-01
  • 2018-04-06
  • 1970-01-01
相关资源
最近更新 更多