gpt4 book ai didi

scala - 尝试在 Play 中运行 Mockito 测试时出现错误消息

转载 作者:行者123 更新时间:2023-12-02 01:50:47 24 4
gpt4 key购买 nike

我正在尝试在我的 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/

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

[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

最佳答案

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

参见 Play documentation on dependencies关于如何做到这一点。

关于scala - 尝试在 Play 中运行 Mockito 测试时出现错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22913572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com