testing - Gradle-Jacoco-JMockit-测试正在挂起而未进行

标签 testing gradle freeze jmockit jacoco

我正在使用Gradle(1.6版至1.9版)来构建Java项目。尝试过Java 1.6或1.7。

src/java  - contains Java source code
test/java - contains test java code

项目成功编译/构建。在构建期间,Junit UNIT测试也成功运行。我只有一个测试,它使用JMockit库。 请注意:在没有测试需要JMockit库的任何其他项目中,同样的jacoco代码也可以正常工作。

JMockit groupid:artifactid:version是:
jmockit:jmockit:1.1

我想启用Jacoco代码覆盖率。我到目前为止已经尝试过的Jacoco版本显示在下面的代码中,该代码存在于我的Gradle构建脚本中。

我在项目的build.gradle文件中添加了以下几行。
apply plugin: 'jacoco'

   jacoco {
                //toolVersion = "0.6.2.201302030002"
          toolVersion = "0.7.0.201403182114"
                //toolVersion = "0.7.1.201404171759" --- trying to find how to make version this working.
                // reportsDir = file("$buildDir/customJacocoReportDir")
   }

   test {
     ignoreFailures = true
     testReportDir = file("$buildDir/reports/tests/UT")
     testResultsDir = file("$buildDir/test-results/UT")

     // Uncomment the following if you need more detailed output.  
     //testLogging.showStandardStreams = true
     //onOutput { descriptor, event ->
     //  logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
     //}

     //Following Jacoco test section is required only in Jenkins instance extra common file
     jacoco {
       //The following vars works ONLY with 1.6 of Gradle
       destPath = file("$buildDir/jacoco/UT/jacocoUT.exec")
       classDumpPath = file("$buildDir/jacoco/UT/classpathdumps")

       //Following vars works only with versions >= 1.7 version of Gradle
       //destinationFile = file("$buildDir/jacoco/UT/jacocoUT.exec")
      //  classDumpFile = file("$buildDir/jacoco/UT/classpathdumps")
     }
   }

   task integrationTest( type: Test) {
     //Always run tests
     outputs.upToDateWhen { false }
     ignoreFailures = true

     testClassesDir = sourceSets.integrationTest.output.classesDir
     classpath = sourceSets.integrationTest.runtimeClasspath

     testReportDir = file("$buildDir/reports/tests/IT")
     testResultsDir = file("$buildDir/test-results/IT")

     //Following Jacoco test section is required only in Jenkins instance extra common file
     jacoco {
        //This works with 1.6
        destPath = file("$buildDir/jacoco/IT/jacocoIT.exec")
        classDumpPath = file("$buildDir/jacoco/IT/classpathdumps")

        //Following works only with versions >= 1.7 version of Gradle
        //destinationFile = file("$buildDir/jacoco/IT/jacocoIT.exec")
        //  classDumpFile = file("$buildDir/jacoco/IT/classpathdumps")
     }
  }

  jacocoTestReport {
      group = "Reporting"
      description = "Generate Jacoco coverage reports after running tests."
      ignoreFailures = true

      executionData = fileTree(dir: 'build/jacoco', include: '**/*.exec')

      reports {
             xml{
                 enabled true
                 //Following value is a file
                 destination "${buildDir}/reports/jacoco/xml/jacoco.xml"
             }
             csv.enabled false
             html{
                 enabled true
                 //Following value is a folder
                 destination "${buildDir}/reports/jacoco/html"
             }
      }

      //sourceDirectories = files(sourceSets.main.allJava.srcDirs)
      sourceDirectories = files('src/java')
      classDirectories =  files('build/classes/main')

      //------------------------------------------
      //additionalSourceDirs = files('test/java')
      //additionalSourceDirs += files('src/java-test')

      //additionalClassDirs = files('build/classes/test')
      //additionalClassDirs += files('build/classes/integrationTest')
      //additionalClassDirs += files('build/classes/acceptanceTest')
      //------------------------------------------
  }

我的问题:
1.当我不使用“apply plugin:'jacoco'”时,:test任务成功运行(我只有一个测试)。但是,当我启用apply plugin:'jacoco'时,然后在:test任务中,我在生成输出期间看到以下行,并且该过程只是卡在那里,坐了几个小时,没有进行。
Starting process 'Gradle Worker 1'. Working directory: /production/jenkinsAKS/workspace/MyProjectSvc Command: /production/jdk1.6.0_03/bin/java -Djava.security.manager=jarjar.org.gradle.processinternal.child.BootstrapSecurityManager -javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.7.0.201403182114.jar_2kiqpmj1hlqbuth11j0qnuarhs/jacocoagent.jar=destfile=build/jacoco/UT/jacocoUT.execappend=true,dumponexit=true,output=file,classdumpdir=build/jacoco/UT/classpathdumps,jmx=false -Dfile.encoding=UTF-8 -ea -cp /production/jenkins/.gradle/caches/1.6/workerMain/gradle-worker.jar jarjar.rg.gradle.process.internal.launcher.GradleWorkerMain
An attempt to initialize for well behaving parent process finished.
Successfully started process 'Gradle Worker 1'
Gradle Worker 1 executing tests.
> Building > :test

我四处搜寻,似乎最新版本的Jacoco库和JMockit库之间有些不兼容,并且有一个修复程序可以解决此问题。 Jacoco 0.7.1.xxxxx的新版本已修复,但我不知道何时可以在Maven存储库中使用它。

任何想法,如何设置javaagent以忽略JACOCO的测试/测试类文件,并且仍然应用jacoco插件。就我而言,应用插件:“jacoco”稍后将存在于全局文件中,即allProjects {....}部分中的/init.d/global-common.gradle文件中。

我尝试了以下操作,但是构建过程仍然卡在:test任务上,直到我在下面取消注释为止。如果我在测试部分中注释掉整个jacoco小节,构建过程仍会卡在:test任务上(似乎就像apply plugin:'jacoco'一样)。如果我取消注释排除,那么我看不到错误,但是没有测试运行,即测试报告的index.html显示没有运行。
test {
     include "**/*"
     jacoco {
        //exclude "**/util/Test*"
     }
}

2.如何在我的build.gradle文件中使用jacoco 0.7.1.xxxx版本(非发行版,即夜间发行版,具有针对此问题的修复程序)。当我取消注释后使用0.7.1.xxx版本时(如上所示),它错误地指出找不到依赖项jacoco:0.7.1.xxxx

3.为了摆脱这个问题,我想我可以设置一个jacoco代理参数,即当它运行时,它将忽略JMOckit / JUnit .jar库或其他东西。查看/找到以下链接:
http://javaee.ch/2012/10/09/jmockit-with-maven-sonar-jacoco-and-jenkinshudson/
https://github.com/jacoco/jacoco/pull/35

累积到第二个链接:

避免该问题的解决方法是将JaUnit类从JaCoCo的考虑范围中排除。我在测试中使用了以下JVM初始化参数,但不包括JUnit和TestNG类:-javaagent:/jacoco-0.7.1/lib/jacocoagent.jar=excludes=junit。:org.junit。:org.testng。
好消息是,我在之前的评论中描述的修复程序也解决了该死锁问题,因为当JMockit对JUnit类进行检测时,JaCoCo将忽略它们。

我正在尝试在jacoco {...}或测试{...}中找到什么变量,我可以设置为执行相同的操作,直到获得新版本的Jacoco或JMockit(已修复)。好像它在测试部分中,即test {..here jvmArgs'...'将被设置。雅各布{...} ..}
http://stevendick.github.io/blog/2012/01/22/jacoco-and-gradle/

4.如果我通过使用“排除” com / xxx / yyy / a / b / c / util / Testname.class”来排除测试类文件,则它可以正常工作,并且我没有看到错误,但是我发现由于这个排除在外,我的测试永远不会运行!!!
这就是为什么它没有挂起。好吧,我希望测试能够运行,而不希望Jacoco处理它。

仅通过让应用插件:build.gradle中的'jacoco'将构建卡在:test任务上。我需要jacoco,因为开发团队还希望看到代码覆盖率的详细信息。

目前,我正在尝试寻找上述答案的答案,感谢您的投入。

最佳答案

最终答案:

Jmockit和Jacoco都检测类文件。 Jmockit在构建过程中首先执行此操作,当jacoco尝试执行相同操作时(在此过程中稍后),它说:“哦,不能检测已经检测的类文件”。较早版本的jacoco和jmockit发生此问题。要查看此错误,请在Gradle构建或--debug期间启用--stacktrace选项。

现在,使用最新的jacoco和jmockit版本,我们可以轻松解决此问题。

如果使用jacoco:

toolVersion="0.7.1.201405082137"

要么
toolVersion="0.7.2.201409121644"

查看此内容:在0.7.1版本中进行的更改
http://www.eclemma.org/jacoco/trunk/doc/changes.html

对于JMockit,您必须使用jmockit版本:至少1.8或更高版本(1.9至1.13)。
org.jmockit:jmockit:1.8

查看此内容:在1.8版本以下的更改:http://jmockit.github.io/changes.html

关于testing - Gradle-Jacoco-JMockit-测试正在挂起而未进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23351111/

相关文章:

Javafx 程序卡住

shell - Erlang:服务器光标卡在命令行上?

android - Android 库模块的最小 build.gradle

angularjs - 如果元素包含值,如何在 Protractor 中退出测试用例

node.js - 使用 knex 和 sqlite3 的 node.js 方法测试永远不会停止

java - 常量 MissingServletRequestParameterException

android - 无法加载类 'com.sun.istack.FinalArrayList'

gradle - Spring-boot 依赖项不适用于 gradle

Python PyQt4 进度条卡住 GUI

javascript - Cypress ,响应主体为 BLOB 而不是 JSON,但 chrome devtools 中的 JSON