Why is scalatest MockitoSugar deprecated?

不问归期 提交于 2021-01-02 14:00:11

问题


I'm new to writing junit tests in Scala and I'm using Mockito to mock objects. I'm also using scalatest_2.12-3.0.4. The ScalaTest documentation (like here) shows the syntax to create the mock using MockitoSugar, i.e.

val mockCollaborator = mock[Collaborator]

Eclipse shows org.scalatest.mock.MockitoSugar crossed out in the import statement, indicating it is deprecated. The only alternative I've found is, don't use MockitoSugar and instead do:

val mockCollaborator = mock(classOf[Collaborator])

This seems to work fine too, so I'm curious what ScalaTest is recommending me to use.

Or for that matter, why else would I use MockitoSugar? Does it have any other features? I've been unable to find any documentation about it, except that everybody seems to use the shorthand mock[] notation.


回答1:


Base on the issue and some comments, the answer should be changed:

  1. the MockitoSugar has been moved to a separate project: https://github.com/scalatest/scalatestplus-mockito
  2. need to add a new dependency to use it

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

testCompile group: 'org.scalatestplus', name: 'mockito-3-4_2.13', version: '3.3.0.0-SNAP3'

origin issue: https://github.com/scalatest/scalatest/issues/1789


As reported in the source you should use org.scalatest.mockito.MockitoSugar instead of org.scalatest.mock.MockitoSugar



来源:https://stackoverflow.com/questions/48552339/why-is-scalatest-mockitosugar-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!