【问题标题】:Jenkins not running TestNG tests via surefire詹金斯没有通过surefire运行TestNG测试
【发布时间】:2013-11-22 19:25:16
【问题描述】:

使用 Maven 和 TestNG 进行本地设置,构建得很好。考虑到为了运行测试,构建有点奇怪,首先需要一个打包的 JAR。所以实际上本地设置运行

#!/bin/bash

mvn clean package -Dmaven.test.skip.exec=true
mvn test

在 Jenkins 上运行时,clean/package 步骤和测试一样成功,但实际上没有运行测试:

[workspace] $ mvn -f some_sub_directory/pom.xml test
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building ...-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ project ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/jobs/...
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ project ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ project ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ project ---
[INFO] Tests are skipped.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.222s
[INFO] Finished at: Fri Nov 22 18:34:00 UTC 2013
[INFO] Final Memory: 11M/89M
[INFO] ------------------------------------------------------------------------
Finished: SUCCESS

似乎surefire插件中的testCompile和test目标没有找到任何测试类。

在 pom.xml 中是否需要额外的配置?

【问题讨论】:

    标签: java maven jenkins


    【解决方案1】:

    测试类的默认和推荐路径是 {basedir}/src/test/java/。 但是你可以在你的 pom.xml 中精确路径

    <build>
       <testSourceDirectory>{basedir}/path/to/test/classes</testSourceDirectory>
        ...
    </build>
    

    【讨论】:

    • 我们确实修改了源文件和测试文件的路径,但是这些是在 pom.xml 中指定的,就像我提到的,在本地可以正常工作。
    【解决方案2】:

    您需要指定需要运行的测试。我相信,它会寻找以 test* 开头的测试。如果您使用的是 testng xml,那么您需要进行设置。查看this link 以获取有关如何以不同方式指定测试的示例。

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      相关资源
      最近更新 更多