直接mock编译会提示缺少参数:
class Test(num: Int) {
def getNum(): Int = num
}
val testMk = mock[Test]
>>not enough arguments for constructor Test
解决办法:
给参数提供默认值
class Test(num: Int = 0) {
def getNum(): Int = num
}
val testMk = mock[Test]
即可。