我有一个Scala对象,它包含一些实用程序功能.这些函数由同一对象中存在的其他函数或其他类/对象调用.是否可以模拟这个对象或函数,以便我可以对它们被调用的类进行单元测试.
例:
object Util {
def methodA() = {
//other code
methodB()
//other code
}
def methodB() = {
//other code
methodC()
//other code
}
def methodC() = { ... }
}
Run Code Online (Sandbox Code Playgroud)
在这里,我从另一个类调用对象函数
class Data {
//other code
def call() = {
//other code
Util.methodA()
//other code
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能对类Data的函数call()进行单元测试?在Java中,我可以为Util创建一个模拟对象,并设置对methodA()调用的期望,但这在Scala中是不可能的,因为没有模拟库支持模拟Scala对象.