【问题标题】:Error message when trying to run a Mockito test in Play尝试在 Play 中运行 Mockito 测试时出现错误消息
【发布时间】:2014-04-07 13:15:20
【问题描述】:

我正在尝试在我的 play 应用程序的测试类中运行以下代码来测试 Mockito:

trait DateWSClient {
  def currentDate: String
}

class DateProvider (dateWS: DateWSClient) {
  def currentYear = {
    dateWS.currentDate.split("/")(0)
  }
}

import org.specs2._
import org.specs2.mock.Mockito

class DateProviderSpec extends mutable.Specification with Mockito {

  "currentYear" should {
    "be the first part of the date returned by the WS" in {
      val clientMock = mock[DateWSClient]
      val formatter = new DateProvider(clientMock)
      clientMock.currentDate returns "2013/08/07"
      formatter.currentYear must beEqualTo("2013")
    }
  }
}

我从这篇文章中得到它:http://workwithplay.com/blog/2013/08/07/mocking-with-mockito/

但是,当我在播放终端中运行“测试”时,我收到以下错误消息:

[error] bad symbolic reference. A signature in MocksCreation.class refers to type MockSettings
[error] in package org.mockito which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling MocksCreation.class.
[error] bad symbolic reference. A signature in MockitoStubs.class refers to term stubbing
[error] in package org.mockito which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling MockitoStubs.class.
[error] two errors found

这里描述了同样的问题:Error using Mockito and Specs2,但是这个解决方案对我没有任何改变。

此错误消息的确切含义是什么?我该如何解决这个问题?

我使用的play版本是:2.1.2

【问题讨论】:

  • 你能用 sbt 打印出你的类路径吗? show externalDependencyClasspath 并检查列表中是否确实存在 "org.mockito" % "mockito-core" % "1.9.5"
  • 不是。如果我添加它,它会起作用吗?如果是这样,我该怎么做?
  • 查看此链接:playframework.com/documentation/2.0/SBTDependencies,了解如何将依赖项添加到您的 Play 项目。
  • 将您之前提供的行添加到构建文件中,谢谢。
  • 我添加了一个答案,以便您可以关闭问题。

标签: scala playframework mocking mockito specs2


【解决方案1】:

"org.mockito" % "mockito-core" % "1.9.5"需要添加到依赖列表中。

请参阅Play documentation on dependencies 了解如何操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 2021-06-10
    相关资源
    最近更新 更多