Using MockitoSugar of scalatestplus-play deprecated

元气小坏坏 提交于 2021-02-10 16:18:51

问题


I'm using "scalatestplus-play" % "5.1.0", and I'm trying to bring MockitoSugar to my class like I did in earlier projects:

class MyTestSpec extends AnyFreeSpec with MockitoSugar

so I can use the mock[MyClass] function and now it docent exists, can't find in the documentation something else.

in my earlier projects I used "scalatestplus-play" % "4.0.3", I'm sure there is a different way now but can't find what it is


回答1:


First option you have, is to use scalatestplus-mockito, where you can find MockitoSugar, as you are used to.

From ScalaTest Testing with mock objects:

You can use any Java mocking framework with ScalaTest, or ScalaMock, a Scala mocking alternative. ScalaTest provides just enough syntax sugar for the three most popular Java mocking frameworks—JMock, EasyMock, and Mockito—to remove boilerplate and clarify the client code.

Another option, as said in the attached link, there are 4 libraries that can be used. The easiest one in my opinion is ScalaMock. To use it you need to extend MockFactory.

It should be imported from:

import org.scalamock.scalatest.MockFactory

The difference is that "scalatestplus-play" % "4.0.3" depends on ScalaTest version 3.0.8 which still had MockitoSugar. "scalatestplus-play" % "5.1.0" depends on ScalaTest 3.1.1 which no longer has it.



来源:https://stackoverflow.com/questions/64883780/using-mockitosugar-of-scalatestplus-play-deprecated

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