当我执行sbt test
以使用spark-testing-base
Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0)) did not equal Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0))
用于
的测试用例val input: Map[String, Any] = Map("digits" -> Seq(1, 2, 3, 4, 5, 6, 7, 8, 9, 0))
val expectedOutput: Map[String, Any] = Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0))
val result = SimpleContext.runTheJOb(session, input)
可以找到最小的示例https://github.com/geoHeil/apache-spark-restAPI-example
直接整个测试用例
class SimpleTest extends FunSuite with SharedSparkContext with DatasetSuiteBase {
test("SimpleContext should multiply input numbers by 3") {
val session = spark
val input: Map[String, Any] = Map("digits" -> Seq(1, 2, 3, 4, 5, 6, 7, 8, 9, 0))
val expectedOutput: Map[String, Any] = Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0))
val result = SimpleContext.runTheJOb(session, input)
assert(expectedOutput === result)
}
}
答案 0 :(得分:4)
您遇到的问题是,使用Array
的Scala ==
(作为Java阵列)无法比较(请参阅this answer获取解释)。
示例:
scala> Array(1,2) == Array(1,2)
res0: Boolean = false
然而,大多数其他集合 可比较:
scala> List(1,2) == List(1,2)
res1: Boolean = true
您的选择是使用其中一个集合(如List
)或使用deep
进行比较:
scala> Array(1,2).deep == Array(1,2).deep
res22: Boolean = true
scala> Array(1,2).deep == Array(1,3).deep
res23: Boolean = false