gpt4 book ai didi

scalatest - 如何使用 ScalaMock 代理模拟?

转载 作者:行者123 更新时间:2023-12-04 21:46:01 31 4
gpt4 key购买 nike

我有一个非常简单的测试,我正在尝试模拟一个特征。测试甚至没有运行,并且失败并显示初始化错误: java.lang.IllegalArgumentException:需求失败:你记得使用 withExpectations 吗?

这是我非常简单的测试:

import org.scalatest._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.ShouldMatchers
import org.scalamock.ProxyMockFactory
import org.scalamock.scalatest.MockFactory

@RunWith(classOf[JUnitRunner])
class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory {
trait Turtle {
def turn(angle: Double)
}

val m = mock[Turtle]
m expects 'turn withArgs (10.0)

describe("A turtle-tester") {
it("should test the turtle") {
m.turn(10.0)
}
}
}

最佳答案

您需要在运行测试之前调用 resetMocks/resetExpectations,最好的方法是(ScalaTest 方式):

class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory with BeforeAndAfter {

before {
resetMocks()
resetExpectations()
}

...
}

关于scalatest - 如何使用 ScalaMock 代理模拟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14283879/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com