ScalaMock,意外调用:<;模拟-1>;在测试之间共享模拟实例时
我将Scala 2.10与ScalaMock 3.6一起使用 我有一个非常简单的测试用例,包含4个测试场景。我已经为这些测试创建了一个ScalaMock,意外调用:<;模拟-1>;在测试之间共享模拟实例时,scala,unit-testing,testing,scalatest,scalamock,Scala,Unit Testing,Testing,Scalatest,Scalamock,我将Scala 2.10与ScalaMock 3.6一起使用 我有一个非常简单的测试用例,包含4个测试场景。我已经为这些测试创建了一个mock对象(模拟文件系统): 现在: 第一个测试不使用任何模拟方法(但需要模拟对象) 第二次测试仅使用现有的模拟方法 第三个测试同时使用现有的和不存在的模拟方法 第四个测试使用所有方法(也createFile) 现在,由于某种原因,当同时运行所有这些测试时,第四个测试失败,并给出以下错误。如果单独运行,它将通过 Unexpected call: <mo
mock
对象(模拟文件系统):
现在:
- 第一个测试不使用任何模拟方法(但需要模拟对象)
- 第二次测试仅使用现有的模拟方法
- 第三个测试同时使用
和现有的
模拟方法不存在的
- 第四个测试使用所有方法(也
)createFile
Unexpected call: <mock-1> FileIO.exist(notExisting)
Expected:
inAnyOrder {
}
Actual:
<mock-1> FileIO.exist(notExisting)
ScalaTestFailureLocation: scala.Option at (Option.scala:120)
org.scalatest.exceptions.TestFailedException: Unexpected call: <mock-1> FileIO.exist(notExisting)
...
意外调用:FileIO.exist(notExisting)
预期:
伊纳约德{
}
实际:
FileIO.exist(notExisting)
ScalaTestFailureLocation:scala.Option位于(Option.scala:120)
org.scalatest.exceptions.testfailedeexception:意外调用:FileIO.exist(notExisting)
...
另一个演练是复制粘贴mock
声明及其在第四个中的行为,它应该{…}
测试场景。然后测试工作(分别进行,并且一起进行)
为什么全局mock
实例失败?
如果需要,我可以尝试准备一个类似的测试场景作为单独的
sbt
项目。混合org.scalatest.OneInstancePerTest
,如下所述:
Unexpected call: <mock-1> FileIO.exist(notExisting)
Expected:
inAnyOrder {
}
Actual:
<mock-1> FileIO.exist(notExisting)
ScalaTestFailureLocation: scala.Option at (Option.scala:120)
org.scalatest.exceptions.TestFailedException: Unexpected call: <mock-1> FileIO.exist(notExisting)
...
class ProcessingOperatorTest extends FlatSpec
with Matchers
with BeforeAndAfterEach
with MockFactory
with OneInstancePerTest {
...
}