Jenkins没有通过surefire运行TestNG测试

时间:2013-11-22 19:25:16

标签: java maven jenkins

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

#!/bin/bash

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

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

[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和测试目标没有找到任何测试类。

pom.xml中是否需要其他配置?

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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