I suggest not using spark-testing-base. Instead you can use the built in capability of SparkContext to be started in the running unit test process.
Example:
import org.scalatest.FunSuite
class AppTest extends FunSuite {
test("test initializing spark context") {
val myLocalInProcessSession = SparkSession
.builder
.master("local[*]") //This is the key config change to make it a local in process spark session.
.appName("myApp")
.getOrCreate()
val list = List(1, 2, 3, 4)
val rdd = myLocalInProcessSession.sparkContext.parallelize(list)
assert(rdd.count === list.length)
myLocalInProcessSession.close()
}
}
You can generalize the creation of the local spark testing session with the tools in FunSuite.
manpreet
Best Answer
2 years ago
I am exploring on how to write unit tests for my spark scala code. I came across spark-testing-base and upon trying to run a few standard examples i get an error
The error is as follows:
I am using IntelliJ IDEA for the same and my build.sbt looks as follows
I have never done unit testing before. I would appreciate any help with this issue