gpt4 book ai didi

斯卡拉 : Error: requirement failed: package stubbing

转载 作者:行者123 更新时间:2023-12-01 19:31:58 32 4
gpt4 key购买 nike

我正在使用 scala 2.12。这是我的 build.sbt 文件

libraryDependencies ++= Seq(
"net.codingwell" %% "scala-guice" % "4.1.0",
"org.scalatest" %% "scalatest" % "3.0.3" % "test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.5.0" % "test"
)

我正在尝试为 Guice 编写一个测试模块,它也使用 Mocking

我试过了

class TestModule extends ScalaModule with MockitoSugar{
val x = mock[TestPartialMock]
override def configure(): Unit = {
bind[Test1]
bind[Test2]
}
}

我收到错误

Error:scalac: Error: requirement failed: package stubbing
java.lang.IllegalArgumentException: requirement failed: package stubbing
at scala.reflect.internal.Types$ModuleTypeRef.<init>(Types.scala:1879)
at scala.reflect.internal.Types$PackageTypeRef.<init>(Types.scala:1897)
at scala.reflect.internal.Types$TypeRef$.apply(Types.scala:2401)
at scala.reflect.internal.Types.typeRef(Types.scala:3553)
at scala.reflect.internal.Types.typeRef$(Types.scala:3536)
at scala.reflect.internal.SymbolTable.typeRef(SymbolTable.scala:16)
at s

我也尝试过

class TestModule extends AbstractModule with ScalaModule with MockitoSugar {
override def configure() = {
}
}

但现在我收到错误

Error:(14, 17) Symbol 'type <none>.stubbing.Answer' is missing from the classpath.
This symbol is required by 'value org.scalatest.mockito.MockitoSugar.defaultAnswer'.
Make sure that type Answer is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.stubbing.
override def configure() = {

然后我尝试了

class TestModule extends AbstractModule with ScalaModule with MockFactory with MockitoSugar {
override def configure() = {
}
}

但我收到此错误

Error:(14, 17) Symbol 'type <none>.mockito.MockSettings' is missing from the classpath.
This symbol is required by 'value org.scalatest.mockito.MockitoSugar.mockSettings'.
Make sure that type MockSettings is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.mockito.
override def configure() = {

在我看来,不可能在同一个类中使用 Guice AbstractFactory 和 MockitoSugar。

最佳答案

我又尝试了一下,终于解决了。将答案留在这里,以便其他人可以找到。

这有效

SBT

"net.codingwell" %% "scala-guice" % "4.1.0",
"org.scalatest" % "scalatest_2.12" % "3.0.3",
"org.mockito" % "mockito-core" % "2.7.22"

现在将类定义为

class TestModule extends AbstractModule with ScalaModule with MockitoSugar {
override def configure() = {}
}

关于斯卡拉 : Error: requirement failed: package stubbing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43696394/

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