代码之家  ›  专栏  ›  技术社区  ›  danclark1820

为什么jacoco:cover会在Play 2.2中报告0次测试、0次失败、0次错误?

  •  2
  • danclark1820  · 技术社区  · 12 年前

    我可以使用 sbt test 。当我使用 sbt jacoco:cover sbt jacoco:test sbt jacoco:report 不管我得到什么 0 tests, 0 errors, 0 failures .Jacobo看到了我的测试文件,但没有看到测试

    项目/Build.scala

    import sbt._
    import Keys._
    import play.Project._
    import de.johoop.jacoco4sbt._
    import JacocoPlugin._
    
    object ApplicationBuild extends Build {
    
       val appName         = "api"
       val appVersion      = "0.1-SNAPSHOT"
    
       lazy val s = playJavaSettings ++ Seq(jacoco.settings:_*)
    
       val appDependencies = Seq(
            "com.novocode" % "junit-interface" % "0.8" % "test"
       )
    
        val main = play.Project(appName, appVersion, appDependencies, settings = s).settings(
    
        **various resolvers**
    
       ).settings(
         jacoco.settings : _*
       ).settings( 
         testOptions in jacoco.Config += Tests.Argument("junitxml")    
       ).settings(
         testOptions in jacoco.Config += Tests.Setup( () => System.setProperty("config.file", "conf/application.conf") )
       ).settings(
         parallelExecution in jacoco.Config := false   
       )
    } 
    

    项目/插件.sbt

    // Use the Play sbt plugin for Play projects 
    addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
    
    // Use jacoco on sbt builds
    libraryDependencies ++= Seq(
        "org.jacoco" % "org.jacoco.core" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
        "org.jacoco" % "org.jacoco.report" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.report", "jar", "jar"))
        )
    
     addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")
    

    我的测试正在进行 测验 目录

    我正在使用:

    • 重头戏2.2.1
    • Java 1.7.0_55
    • 标准偏差0.13.2

    我在网上为遇到同一问题的人找到的大多数答案都是 parallelExecution 未设置为 false 。当我检查时 sbt jacoco:parallelExecution api 设置到的目录 假的 但当我跑的时候 sbt-jacoco:并行执行 project test 设置到的目录 true .

    3 回复  |  直到 12 年前
        1
  •  1
  •   danclark1820    12 年前

    我一加上它就开始工作了

    .settings(
      Keys.fork in jacoco.Config := true    
    )
    

    到我的Build.scala文件。我希望我能解释更多这是如何工作的,但它仍然有点模糊。

    谢谢大家的回答。它现在在本地运行得很好,但仍然在Jenkins中运行0个测试。

        2
  •  0
  •   Jacek Laskowski    12 年前

    我刚刚用最新的Play2.3.1和jacoco4sbt 2.1.5对其进行了第一次测试,结果毫无问题。老实说,我自己都很惊讶,事情进展得如此顺利。

    您不需要以下内容 项目/插件.sbt :

    // Use jacoco on sbt builds
    libraryDependencies ++= Seq(
        "org.jacoco" % "org.jacoco.core" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
        "org.jacoco" % "org.jacoco.report" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.report", "jar", "jar"))
    )
    

    为了测试它,我首先使用Typesafe Activator创建了Play应用程序 play-scala 样板

    ➜  sandbox  activator new play-jacoco play-scala
    
    Fetching the latest list of templates...
    
    OK, application "play-jacoco" is being created using the "play-scala" template.
    
    To run "play-jacoco" from the command line, "cd play-jacoco" then:
    /Users/jacek/sandbox/play-jacoco/activator run
    
    To run the test for "play-jacoco" from the command line, "cd play-jacoco" then:
    /Users/jacek/sandbox/play-jacoco/activator test
    
    To run the Activator UI for "play-jacoco" from the command line, "cd play-jacoco" then:
    /Users/jacek/sandbox/play-jacoco/activator ui
    
    ➜  sandbox  cd play-jacoco
    

    然后我跑了 activator 进入shell并执行 test .

    ➜  play-jacoco  activator
    [info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
    [info] Loading project definition from /Users/jacek/sandbox/play-jacoco/project
    [info] Updating {file:/Users/jacek/sandbox/play-jacoco/project/}play-jacoco-build...
    [info] Resolving org.fusesource.jansi#jansi;1.4 ...
    [info] Done updating.
    [info] Set current project to play-jacoco (in build file:/Users/jacek/sandbox/play-jacoco/)
    [play-jacoco] $ test
    [info] Updating {file:/Users/jacek/sandbox/play-jacoco/}root...
    [info] Resolving jline#jline;2.11 ...
    [info] Done updating.
    [info] Compiling 5 Scala sources and 1 Java source to /Users/jacek/sandbox/play-jacoco/target/scala-2.11/classes...
    [info] Compiling 2 Scala sources to /Users/jacek/sandbox/play-jacoco/target/scala-2.11/test-classes...
    [info] IntegrationSpec
    [info]
    [info] Application should
    [info] + work from within a browser
    [info]
    [info] Total for specification IntegrationSpec
    [info] Finished in 2 seconds, 615 ms
    [info] 1 example, 0 failure, 0 error
    [info] ApplicationSpec
    [info]
    [info] Application should
    [info] + send 404 on a bad request
    [info] + render the index page
    [info]
    [info] Total for specification ApplicationSpec
    [info] Finished in 130 ms
    [info] 2 examples, 0 failure, 0 error
    [info] Passed: Total 3, Failed 0, Errors 0, Passed 3
    [success] Total time: 17 s, completed Jul 11, 2014 7:57:23 PM
    

    下列的 the Wiki on jacoco4sbt plugin site on GitHub ,然后我添加了 jacoco.settings 建筑.sbt 在顶级目录中。我还补充了 addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5") 项目/插件.sbt .

    未进行其他更改。

    reload 激活激活器外壳以加载更改。

    [play-jacoco] $ reload
    [info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
    [info] Loading project definition from /Users/jacek/sandbox/play-jacoco/project
    [info] Updating {file:/Users/jacek/sandbox/play-jacoco/project/}play-jacoco-build...
    [info] Resolving org.fusesource.jansi#jansi;1.4 ...
    [info] Done updating.
    [info] Set current project to play-jacoco (in build file:/Users/jacek/sandbox/play-jacoco/)
    

    当我跑步时 jacoco:cover 插件执行并显示结果。

    [play-jacoco] $ jacoco:cover
    [info] Updating {file:/Users/jacek/sandbox/play-jacoco/}root...
    [info] Resolving org.jacoco#org.jacoco.agent;0.7.0.201403182114 ...
    [info] Done updating.
    [info] ApplicationSpec
    [info]
    [info] Application should
    [info] + send 404 on a bad request
    [info] + render the index page
    [info]
    [info] Total for specification ApplicationSpec
    [info] Finished in 22 ms
    [info] 2 examples, 0 failure, 0 error
    [info] IntegrationSpec
    [info]
    [info] Application should
    [info] + work from within a browser
    [info]
    [info] Total for specification IntegrationSpec
    [info] Finished in 22 ms
    [info] 1 example, 0 failure, 0 error
    [info] Passed: Total 3, Failed 0, Errors 0, Passed 3
    [info]
    [info] ------- Jacoco Coverage Report --------
    [info]
    [info] Lines: 57.5% (>= required 0.0%) covered, 34 of 80 missed, OK
    [info] Instructions: 71.94% (>= required 0.0%) covered, 523 of 1864 missed, OK
    [info] Branches: 27.78% (>= required 0.0%) covered, 26 of 36 missed, OK
    [info] Methods: 81.94% (>= required 0.0%) covered, 41 of 227 missed, OK
    [info] Complexity: 76.73% (>= required 0.0%) covered, 57 of 245 missed, OK
    [info] Class: 57.14% (>= required 0.0%) covered, 12 of 28 missed, OK
    [info] Check /Users/jacek/sandbox/play-jacoco/target/scala-2.11/jacoco for detail report
    [info]
    [success] Total time: 4 s, completed Jul 11, 2014 8:01:00 PM
    

    这是项目的状态。

    [play-jacoco] $ about
    [info] This is sbt 0.13.5
    [info] The current project is {file:/Users/jacek/sandbox/play-jacoco/}root 1.0-SNAPSHOT
    [info] The current project is built against Scala 2.11.1
    [info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, play.Play, play.PlayJava, play.PlayScala, play.twirl.sbt.SbtTwirl, com.typesafe.sbt.jse.SbtJsEngine, com.typesafe.sbt.jse.SbtJsTask, com.typesafe.sbt.web.SbtWeb, com.typesafe.sbt.webdriver.SbtWebDriver, com.typesafe.sbt.coffeescript.SbtCoffeeScript, com.typesafe.sbt.less.SbtLess, com.typesafe.sbt.jshint.SbtJSHint, com.typesafe.sbt.rjs.SbtRjs, com.typesafe.sbt.digest.SbtDigest, com.typesafe.sbt.mocha.SbtMocha, net.virtualvoid.sbt.graph.Plugin, com.timushev.sbt.updates.UpdatesPlugin, com.typesafe.sbteclipse.plugin.EclipsePlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.SbtNativePackager, de.johoop.jacoco4sbt.JacocoPlugin
    [info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
    
        3
  •  0
  •   lpiepiora    12 年前

    您必须删除以下行。

    testOptions in jacoco.Config += Tests.Argument("junitxml")
    

    opiton不支持此选项。有关支持的选项列表,请检查 the documentation