2014-07-11 70 views
2

我可以使用sbt test運行我的測試。當我運行測試使用sbt jacoco:coversbt jacoco:testsbt jacoco:report但是我得到0 tests, 0 errors, 0 failures。 Jacoco看到我的測試文件,但沒有測試爲什麼jacoco:在Play 2.2中測試覆蓋報告0次測試,0次失敗,0次錯誤?

項目/ 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 
    ) 
} 

項目/ plugins.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
  • SBT 0.13.2

大多數我在網上找到了運行到同一問題的人的答案是的parallelExecution問題不被設置爲false。當我在api目錄中檢查sbt jacoco:parallelExecution時,它將設置爲false。但是當我在projecttest目錄中運行sbt jacoco:parallelExecution時,它被設置爲true

+0

您可以將'sbt --version'和'sbt about'的輸出添加到問題中嗎? –

回答

1

它開始工作,一旦我加入

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

我Build.scala文件。我希望我能解釋更多關於這是如何工作的,但它仍然有點模糊。

謝謝大家的答案。它現在在本地運行良好,但仍在Jenkins中運行0個測試。

0

我剛剛用最新的Play 2.3.1和jacoco4sbt 2.1.5進行了第一次測試,它沒有任何問題。老實說,我很驚訝自己有多順利。

您不需要按照項目/ plugins.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")) 
) 

爲了測試它,我首先創建使用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進入外殼並執行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.settingsbuild.sbt。我還添加了addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")project/plugins.sbt

沒有其他改變。

I 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 
0

您必須刪除以下行。

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

這是不支持的opiton。對於支持的選項列表檢查the documentation

相關問題