scala - sbt 测试未通过我的 spark 测试套件,而 intellij 测试有效
问题描述
我正在尝试测试一个吃和处理 DataFrames 的类的行为。
继之前的问题之后:如何在 Spark 2.0+ 中编写单元测试?我尝试使用贷款模式以下列方式运行我的测试:我有一个 SparkSession 提供者特征:
/**
* This trait allows to use spark in Unit tests
* https://stackoverflow.com/questions/43729262/how-to-write-unit-tests-in-spark-2-0
*/
trait SparkSetup {
def withSparkSession(testMethod: SparkSession => Any) {
val conf = new SparkConf()
.setMaster("local")
.setAppName("Spark test")
val sparkSession = SparkSession
.builder()
.config(conf)
.enableHiveSupport()
.getOrCreate()
try {
testMethod(sparkSession)
}
// finally sparkSession.stop()
}
}
我在我的测试课中使用:
class InnerNormalizationStrategySpec
extends WordSpec
with Matchers
with BeforeAndAfterAll
with SparkSetup {
...
"A correct contact message" should {
"be normalized without errors" in withSparkSession{ ss => {
import ss.implicits._
val df = ss.createDataFrame(
ss.sparkContext.parallelize(Seq[Row](Row(validContact))),
StructType(List(StructField("value", StringType, nullable = false))))
val result = target.innerTransform(df)
val collectedResult: Array[NormalizedContactHistoryMessage] = result
.where(result.col("contact").isNotNull)
.as[NormalizedContactHistoryMessage]
.collect()
collectedResult.isEmpty should be(false) // There should be something
collectedResult.length should be(1) // There should be exactly 1 message...
collectedResult.head.contact.isDefined should be(true) // ... of type contact.
}}
}
...
}
当尝试使用 IntelliJ 工具运行我的测试时,以这种方式编写的所有测试都可以工作(一次运行 Spec 类),但是,sbt test
来自终端的命令会使所有测试失败。
我还以为是因为并行性,所以我添加了
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
在我的 sbt 设置中,但没有用。
这是我收到的堆栈跟踪:https ://pastebin.com/LNTd3KGW
有什么帮助吗?
谢谢
解决方案
推荐阅读
- jhipster - 如何在蓝图中扩展通用子生成器?
- r - R 的 Huxtable 包:使用 huxreg() 的回归表中两个模型列表之间的颜色编码差异
- react-native - 如何使用 HeaderComponent 转到 React Native Flatlist 的顶部
- swift - 如何在 alpha == 0 的 UIImage 中获取像素
- php - 作曲家自动加载文件在 laradock 中不起作用
- java - 在 Kotlin-Android 中暂停正在进行的用户交互迭代过程
- css - 如何将元素垂直放置在中心和
- javascript - 如何确保使用触发器仅发送一次
- alfresco - 如何阻止发起者访问 Alfresco BPM 中的其他任务?
- sql-server - 如何使用 SQL 从表列中仅检索小于给定的值