为什么不推荐使用 scalatest MockitoSugar?

编程入门 行业动态 更新时间:2024-10-19 14:30:27
本文介绍了为什么不推荐使用 scalatest MockitoSugar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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 在导入语句中显示 org.scalatest.mock.MockitoSugar 被划掉,表明它已被弃用.我发现的唯一替代方法是,不要使用 MockitoSugar 而是使用:

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])

这似乎也很好用,所以我很好奇 ScalaTest 推荐我使用什么.

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

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

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.

推荐答案

基于 issue 和一些评论,答案应该改变:

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

  • MockitoSugar 已移至单独的项目:github/scalatest/scalatestplus-mockito
  • 需要添加一个新的依赖来使用它
  • mvnrepository/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'

    起源问题:github/scalatest/scalatest/issues/1789

    如source 你应该使用 org.scalatest.mockito.MockitoSugar 而不是 org.scalatest.mock.MockitoSugar

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

    更多推荐

    为什么不推荐使用 scalatest MockitoSugar?

    本文发布于:2023-11-25 15:29:48,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1630306.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:推荐使用   scalatest   MockitoSugar

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!