【问题标题】:Why is scalatest MockitoSugar deprecated?为什么不推荐使用scalatest MockitoSugar?
【发布时间】:2018-07-11 03:55:37
【问题描述】:

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

val mockCollaborator = mock[Collaborator]

Eclipse 显示 org.scalatest.mock.MockitoSugar 在 import 语句中被划掉,表明它已被弃用。我发现的唯一选择是,不要使用 MockitoSugar 而是使用:

val mockCollaborator = mock(classOf[Collaborator])

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

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

【问题讨论】:

    标签: scala unit-testing mockito scalatest


    【解决方案1】:

    基于issue和一些cmets,答案应该改了:

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

    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'
    

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


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

    【讨论】:

    猜你喜欢
    • 2021-03-01
    • 2016-02-23
    • 2017-11-04
    • 2011-10-22
    • 2011-04-11
    • 2021-10-12
    • 2012-12-07
    • 2012-05-16
    • 2020-06-29
    相关资源
    最近更新 更多