火花单元测试

时间:2016-12-16 22:04:39

标签: unit-testing apache-spark apache-spark-2.0

我的整个build.sbt是:

name := """sparktest"""

version := "1.0.0-SNAPSHOT"

scalaVersion := "2.11.8"

scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8", "-Xexperimental")

parallelExecution in Test := false

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "2.0.2",
  "org.apache.spark" %% "spark-sql" % "2.0.2",
  "org.apache.avro" % "avro" % "1.8.1",

  "org.scalatest" %% "scalatest" % "3.0.1" % "test",
  "com.holdenkarau" %% "spark-testing-base" % "2.0.2_0.4.7" % "test"
)

我有一个简单的测试。显然,这只是一个起点,我想测试更多:

package sparktest

import com.holdenkarau.spark.testing.DataFrameSuiteBase

import org.scalatest.FunSuite

class SampleSuite extends FunSuite with DataFrameSuiteBase {
  test("simple test") {
    assert(1 + 1 === 2)
  }
}

我运行sbt clean test但失败了:

Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf$ConfVars

对于我的开发环境,我使用的是spark-2.0.2-bin-hadoop2.7.ta​​r.gz

我是否必须以任何方式配置此环境?显然,HiveConf是一个传递的Spark依赖

1 个答案:

答案 0 :(得分:2)

正如@ daniel-de-paula在评论中提到的那样,您需要将spark-hive添加为显式依赖项(如果您不在应用程序中使用hive,则可以将其限制为测试范围)。 spark-hive不是spark-core的传递依赖,这就是这个错误发生的原因。 spark-hive被作为依赖项从spark-testing-base中排除,因此只进行RDD测试的人不需要将其添加为依赖项。