为什么 scalatest MockitoSugar 被弃用?

moj*_*ken 4 unit-testing scala mockito scalatest

我是在 Scala 中编写 junit 测试的新手,我正在使用 Mockito 来模拟对象。我也在用scalatest_2.12-3.0.4。ScalaTest 文档(如此)显示了使用 MockitoSugar 创建模拟的语法,即

val mockCollaborator = mock[Collaborator]
Run Code Online (Sandbox Code Playgroud)

Eclipseorg.scalatest.mock.MockitoSugar在导入语句中显示划线,表明它已被弃用。我发现的唯一替代方法是,不要使用 MockitoSugar,而是这样做:

val mockCollaborator = mock(classOf[Collaborator])
Run Code Online (Sandbox Code Playgroud)

这似乎也工作得很好,所以我很好奇 ScalaTest 推荐我使用什么。

或者就此而言,我为什么要使用 MockitoSugar?它还有其他功能吗?我找不到任何有关它的文档,除了每个人似乎都使用速记mock[]符号。

Luc*_* T. 6

依据问题和一些评论,答案应该更改\xef\xbc\x9a

\n
    \n
  1. MockitoSugar移至单独的项目:https://github.com/scalatest/scalatestplus-mockito
  2. \n
  3. 需要添加新的依赖项才能使用它
  4. \n
\n

https://mvnrepository.com/artifact/org.scalatestplus/mockito-3-4_2.13/3.3.0.0-SNAP3

\n
testCompile group: \'org.scalatestplus\', name: \'mockito-3-4_2.13\', version: \'3.3.0.0-SNAP3\'\n
Run Code Online (Sandbox Code Playgroud)\n

起源问题: https: //github.com/scalatest/scalatest/issues/1789

\n
\n

正如源中所报告的,您应该使用org.scalatest.mockito.MockitoSugar而不是org.scalatest.mock.MockitoSugar

\n

  • 在版本 3.0.6 中,该类再次移动到“org.scalatestplus.mockito.MockitoSugar” (3认同)
  • 现在它也已转移到其他依赖项。请参阅https://mvnrepository.com/artifact/org.scalatestplus/scalatestplus-mockito_2.13/1.0.0-M2 (2认同)