我正在尝试测试一个函数,但是我正在测试的函数调用了我想要存根的特征函数。我似乎无法使用 ScalaMock 存根此函数,因为我无法模拟该对象。
trait[A<:CommonReturn] commonTrait[A] {
def commonFunction(s:String):(String,String) = {
("Hello","World")
}
def testMe(s:String) : A
}
然后这个特征被许多对象扩展,每个对象都实现了 commonTrait 并返回它们特定的公共返回子类型。
object ob extends commonTrait[ConcreteType] {
override def testMe(s:String){
val(x,y) = commonFunction(s)
val z = "unique logic"
ConcreteType(x,y,z)
}
}
因此,我现在正在尝试测试 ob.testMe,但是我似乎无法模拟 ob 对象,因此无法存根 commonFunction。
这是因为我的架构吗?或者是否可以使用 scalamock 模拟对象并使用 scalatest?
val mocked = mock[ob]
(mocked.commonFunction _).expect(*).returning("test","test")
这不编译。