Skip to content

Instantly share code, notes, and snippets.

@JoshRosen
Created January 10, 2013 00:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshRosen/4498172 to your computer and use it in GitHub Desktop.
Save JoshRosen/4498172 to your computer and use it in GitHub Desktop.
Code coverage for Spark tests using JaCoCo
$ sbt/sbt "jacoco:cover"
$ open core/target/scala-2.9.2/jacoco/html/index.html
diff --git a/project/SparkBuild.scala b/project/SparkBuild.scala
index 842d0fa..3219ec0 100644
--- a/project/SparkBuild.scala
+++ b/project/SparkBuild.scala
@@ -4,6 +4,8 @@ import Keys._
import sbtassembly.Plugin._
import AssemblyKeys._
import twirl.sbt.TwirlPlugin._
+import de.johoop.jacoco4sbt._
+import JacocoPlugin._
// For Sonatype publishing
//import com.jsuereth.pgp.sbtplugin.PgpKeys._
@@ -17,6 +19,7 @@ object SparkBuild extends Build {
//val HADOOP_VERSION = "2.0.0-mr1-cdh4.1.1"
//val HADOOP_MAJOR_VERSION = "2"
+
lazy val root = Project("root", file("."), settings = rootSettings) aggregate(core, repl, examples, bagel)
lazy val core = Project("core", file("core"), settings = coreSettings)
@@ -92,6 +95,7 @@ object SparkBuild extends Build {
"com.novocode" % "junit-interface" % "0.8" % "test"
),
parallelExecution := false,
+ parallelExecution in jacoco.Config := false,
/* Workaround for issue #206 (fixed after SBT 0.11.0) */
watchTransitiveSources <<= Defaults.inDependencies[Task[Seq[File]]](watchSources.task,
const(std.TaskExtra.constant(Nil)), aggregate = true, includeRoot = true) apply { _.join.map(_.flatten) },
@@ -103,7 +107,7 @@ object SparkBuild extends Build {
publishMavenStyle in MavenCompile := true,
publishLocal in MavenCompile <<= publishTask(publishLocalConfiguration in MavenCompile, deliverLocal),
publishLocalBoth <<= Seq(publishLocal in MavenCompile, publishLocal).dependOn
- )
+ ) ++ Seq(jacoco.settings:_*)
val slf4jVersion = "1.6.1"
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 4d0e696..226bd81 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -16,3 +16,9 @@ addSbtPlugin("cc.spray" %% "sbt-twirl" % "0.5.2")
//resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
//addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
+
+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" % "1.2.3")
@JoshRosen
Copy link
Author

Note that the coverage may be an underestimate since it doesn't seem to detect code executed in UDFs:

JaCoCo coverage report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment