如何避免在将maven项目集成到hudson / jenkins时多次运行测试

时间:2012-03-27 16:07:04

标签: maven hudson jenkins

我已经在Hudson中集成了一个按顺序调用的maven 3项目:

clean tomcat:redeploy site sonar:sonar

问题是JUnit运行了3次,这里是我获得的目标序列:

>[INFO] [clean:clean {execution: default-clean}]  
>[INFO] [gwt:i18n {execution: default}]  
>[INFO] [gwt:generateAsync {execution: default}]  
>[INFO] [resources:resources {execution: default-resources}]  
>[INFO] [compiler:compile {execution: default-compile}]  
>[INFO] [checkstyle:check {execution: mycom-check}]  
>[INFO] [checkstyle:check {execution: extended-check}]  
>[INFO] [resources:copy-resources {execution: default}]  
>[INFO] [gwt:i18n {execution: default}]  
>[INFO] [gwt:generateAsync {execution: default}]  
>[INFO] [resources:resources {execution: default-resources}]  
>[INFO] [compiler:compile {execution: default-compile}]  
>[INFO] [checkstyle:check {execution: mycom-check}]  
>[INFO] [checkstyle:check {execution: extended-check}]  
>[INFO] [resources:copy-resources {execution: default}]  
>[INFO] [resources:testResources {execution: default-testResources}]  
>[INFO] [compiler:testCompile {execution: default-testCompile}]  
>[INFO] **[surefire:test {execution: default-test}]**  
>[INFO] [gwt:compile {execution: default}]  
>[INFO] [war:war {execution: default-war}]  
>[INFO] [***tomcat:redeploy*** {execution: default-cli}]  
>[INFO] [gwt:i18n {execution: default}]  
>[INFO] [gwt:generateAsync {execution: default}]  
>[INFO] [resources:resources {execution: default-resources}]  
>[INFO] [compiler:compile {execution: default-compile}]  
>[INFO] [checkstyle:check {execution: mycom-check}]  
>[INFO] [checkstyle:check {execution: extended-check}]  
>[INFO] [resources:copy-resources {execution: default}]  
>[INFO] [cobertura:instrument {execution: default-instrument}]  
>[INFO] [cobertura:instrument {execution: default-instrument}]  
>[INFO] [resources:testResources {execution: default-testResources}]  
>[INFO] [compiler:testCompile {execution: default-testCompile}]  
>[INFO] **[surefire:test {execution: default-test}]**  
>[INFO] [cobertura:cobertura {execution: default-cli}]  
>[INFO] [resources:testResources {execution: default-testResources}]  
>[INFO] [compiler:testCompile {execution: default-testCompile}]  
>[INFO] [surefire:test {execution: default-test}]  
>[INFO] [***site:site*** {execution: default-site}]  
>[INFO]    task-segment: [sonar:sonar] (aggregator-style)  
>[INFO] [sonar:sonar {execution: default-cli}]  
>[INFO] [***sonar:sonar*** {execution: default-sonar}]  
>[INFO] [gwt:i18n {execution: default}]  
>[INFO] [gwt:generateAsync {execution: default}]  
>[INFO] [resources:resources {execution: default-resources}]  
>[INFO] [compiler:compile {execution: default-compile}]  
>[INFO] [checkstyle:check {execution: mycom-check}]  
>[INFO] [checkstyle:check {execution: extended-check}]  
>[INFO] [resources:copy-resources {execution: default}]  
>[INFO] [cobertura:instrument {execution: default-instrument}]  
>[INFO] [resources:testResources {execution: default-testResources}]  
>[INFO] [compiler:testCompile {execution: default-testCompile}]  
>[INFO] **[surefire:test {execution: default-test}]**  
>[INFO] [cobertura:cobertura {execution: default-cli}]  

这是非常有问题的,因为Hudson中的一个错误使得它三次计数3次: http://issues.hudson-ci.org/browse/HUDSON-1557
然而它看起来在詹金斯修复: https://issues.jenkins-ci.org/browse/JENKINS-2068

我感到惊讶的是,“cobertura”单元测试运行两次。 我是maven的新手,所以我不太清楚“生命周期步骤”解决方案。在蚂蚁中,完成了目标分辨率,以便每个目标只执行一次。 我的问题是:

  • 为什么这些Cobertura单元测试运行两次?是我的配置中的缺陷,在Maven中,在插件中?
  • 我可以测试什么来试图理解?
  • 一般来说,是否有任何Maven命令可用于预览将在不执行真实执行的情况下执行的序列?我没有发现任何相关信息,但会发现它非常有用。

感谢您的建议。

1 个答案:

答案 0 :(得分:0)

  

为什么这些Cobertura单元测试运行两次?是我的缺点   在Maven中,在一个插件中配置?

tomcat:redeploysonar:sonar都在运行cobertura。这是maven配置的一个问题,可以修复。

  

我可以测试什么来试图理解?

通常,您可以单独运行每个目标,看看它的作用。

  

一般来说,是否有任何Maven命令可用于预览将在不执行真实执行的情况下执行的序列?我没有发现任何相关信息,但会发现它非常有用。

通常,每个目标的文档都会指出为该目标执行的生命周期阶段。 maven中没有dry-run选项。