繁体   English   中英

使用 scalamock:找不到类型错误的证据参数的隐式值

[英]Using scalamock: Could not find implicit value for evidence parameter of type error

我正在为我的 spark/scala 应用程序编写单元测试。 我也在使用 scalamock 来模拟对象,特别是 Session / Session Factory。

在我的一个测试课程中,我尝试模拟 Session。例如:

val mockedSession = mock[Session]

但是,我收到此错误:

could not find implicit value for evidence parameter of type
org.scalamock.util.Defaultable[org.hibernate.SimpleNaturalldLoadAccess]

无论我模拟 object,我都会收到类似的错误。 格式看起来是正确的。

文档中的“高级主题/原始类型”部分:

"mocking a java method with raw type" should "work" in {
  implicit val d = new Defaultable[java.util.Enumeration[_]] {
    override val default = null
  }
  implicit val d2 = new Defaultable[java.util.Map[_, _]] {
    override val default = null
  }
  
  val mockedRaw = mock[RawTypeInterface]
}

在我的例子中,只需导入有问题的类型即可解决错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM