I wrote a simple Scala code to practice Scala Test:
object Job {
def main(args: Array[String]) = {
val sc = new SparkContext()
println(reduceWithSum(sc))
}
def reduceWithSum(sc: SparkContext): MyClass = {
val data = Array(1, 2, 3, 4, 5)
val distData = sc.parallelize(data)
val distDataValue = distData.map(MyClass(_))
distDataValue.reduce(MyClass.sum)
}
}
I know it is easy to write a test code for reduceWithSum() but it seems very hard for me to write a test code for main(). Any hint?
Here is a sample testing code I wrote:
class JobTest extends FlatSpec with Matchers {
val conf = new SparkConf().setMaster("local[*]").setAppName("Test")
val testSc = new SparkContext(conf)
it should "reduce correctly" in {
Job.reduceWithSum(testSc) shouldBe MyClass(15)
}